I trying to understand this piece of code
Function.prototype.method = function (name, fn) {
this.prototype[name] = fn;
return this;
};
what does “this” refering to in the function body ?
Is it refering to Function.prototype ?
Is it trying to add a member to
Function.prototype.prototype , namely Function.prototype.prototype[name] ?
Function in
Function.prototypeare called onFunctioninstances.Therefore,
thisrefers to the function you called it on.this.prototypewould refer to the prototype of the function you called it on.For example: