我想大多数人都看过以下代码片段:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Run Code Online (Sandbox Code Playgroud)
我也知道它会影响所有函数,因为它们都是Function创建的对象,因此它们可以访问名为"method"的方法,但是我很困惑为什么函数本身也可以访问"方法",如下所示:
Function.method('test', function () {return 1;});
Run Code Online (Sandbox Code Playgroud)