+ 2

Why are we using the syntax objectName.propertyName to access the object method instead of objectName.methodName ?

Why are we using the syntax objectName.propertyName to access the object method instead of objectName.methodName (in the blow example provided by Solo Learn) like we do when we define the method outside of constructor function? function person(name, age) { this.name = name; this.age = age; this.changeName = function (name) { this.name = name; } } var p = new person("David", 21); p.changeName("John"); document.write(p.name);

21st Mar 2017, 4:31 PM
Waqas Shah
Waqas Shah - avatar
1 Antwort
+ 1
Because to call a method you method (parameters);
23rd Mar 2017, 6:07 AM
Eldar Bakerman