简体   繁体   English

Douglas Crockford的书中关于Function.prototype的“方法”

[英]'method' on Function.prototype in Douglas Crockford's book

In Crockford's book 'method' is added to Function.prototype 在Crockford的书中,“方法”被添加到Function.prototype

In my browser console, I did this 在我的浏览器控制台中,我做到了

  1. Function.method --> undefined Function.method >未定义
  2. Function.prototype.method=function(name,func){this.prototype[name]=func; return this;} --> function(name,func){this.prototype[ame]=func; return this;}
  3. (function(){}).method --> function(name,func){this.prototype[name]=func; return this;}
  4. Function.method --> function(name,func){this.prototype[name]=func; return this;}

I can understand step 3, where a function literal has 'method' defined 我可以理解步骤3,其中函数文字已定义“方法”

But how come in step 4, Function.method, which was undefined in step 1, suddenly has 'method' defined. 但是在步骤1中未定义的步骤4,Function.method中突然出现了已定义的“方法”。

Is Function an instance of itself ? Function是其自身的实例吗?

Is Function an instance of itself ? Function是其自身的实例吗?

Yes . 是的

Function instanceof Function;
> true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM