+ 1

How do you differentiate a method and a variable of an object?

They are named the same but method is just put as a function outside of the object.

11th Mar 2016, 4:47 PM
yujjjkjh
3 Réponses
+ 2
A method, a function within an object, will have parenthesis after its name e.g. function methodName () { //code } A property, a variable within an object, will not have parenthesis after its name e.g. var propertyName; A method (function) or a property (variable) belonging to an object will be called based on the object they belong to: objectName.methodName (); objectName.propertyName;
31st Jul 2016, 2:47 AM
Max Beck
Max Beck - avatar
+ 1
I looked it up and was led to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof. (Note that methods are "functions".) So if you ever need your code to do the "differentiating" you ask for, call on -->typeof object.someMysteriousProperty<-- and wherever you put that, you'll return "function" if it's a method, or "number"/"string"/"object"/etc. if it's not.
10th Jun 2016, 2:40 PM
Matt V
Matt V - avatar
- 2
a variable holds a data type
19th Jun 2016, 5:13 AM
hani chrife
hani chrife - avatar