+ 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);
1 ответ
+ 1
Because to call a method you method (parameters);