Is There Any Difference Between Calling Function In FunctionName.prototype.methodName() And FunObject.methodName()?
If I create a function constructor like this function ClassName() { } and then I write methods for this constructor like this ClassName.prototype.a = function() { console.log('A E
Solution 1:
The difference is function context
function ClassName(name) {
this.name = name;
}
ClassName.prototype.a = function() {
console.log("A Executed", this.name, this === obj, this === ClassName.prototype)
}
var obj = new ClassName('test')
obj.a();
ClassName.prototype.a()
Post a Comment for "Is There Any Difference Between Calling Function In FunctionName.prototype.methodName() And FunObject.methodName()?"