javascript - Douglas Crockford 书中 Function.prototype 上的“方法”

标签 javascript

在 Crockford 的书中,“方法”被添加到 Function.prototype

在我的浏览器控制台中,我这样做了

  1. 函数.方法 --> 未定义
  2. Function.prototype.method=function(name,func){this.prototype[name]=func;返回这个;} --> 函数(名称,func){this.prototype[ame]=func;返回这个;}
  3. (function(){}).method --> 函数(名称,func){this.prototype[名称]=func;返回这个;}
  4. 函数.方法 --> 函数(名称,func){this.prototype[名称]=func;返回这个;}

我可以理解第 3 步,其中函数文字定义了“方法”

但是为什么在步骤 4 中,在步骤 1 中未定义的 Function.method 突然定义了“method”。

函数是它自身的实例吗?

最佳答案

Is Function an instance of itself ?

Yes .

Function instanceof Function;
> true

关于javascript - Douglas Crockford 书中 Function.prototype 上的“方法”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199807/

相关文章:

javascript - 如何在非点击事件触发时停止重定向到页面

javascript - onelogin API 列出 Office 365 中的连接器

javascript - 从 Shadow DOM 中获取 ElementById

javascript - 在 for 循环中使用 d3

javascript - Angular ui-router中的双向子/资源关系

javascript - 将 daterangepicker 转换为 Angular 指令

javascript - 有没有办法从 MSXML XPath 求值器获取非节点结果?

javascript - 我想知道 Array.prototype.sort 基本上是如何工作的 排序函数的polyfill

javascript - 我如何让按钮折叠该部分?

javascript - 使用 Jasmine 测试 Angular2/TypeScript 管道