在 Crockford 的书中,“方法”被添加到 Function.prototype
在我的浏览器控制台中,我这样做了
函数.方法
--> 未定义Function.prototype.method=function(name,func){this.prototype[name]=func;返回这个;} --> 函数(名称,func){this.prototype[ame]=func;返回这个;}
(function(){}).method --> 函数(名称,func){this.prototype[名称]=func;返回这个;}
函数.方法 --> 函数(名称,func){this.prototype[名称]=func;返回这个;}
我可以理解第 3 步,其中函数文字定义了“方法”
但是为什么在步骤 4 中,在步骤 1 中未定义的 Function.method 突然定义了“method”。
函数是它自身的实例吗?
最佳答案
关于javascript - Douglas Crockford 书中 Function.prototype 上的“方法”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199807/