否";函数.方法“;用JavaScript?

否";函数.方法“;用JavaScript?,javascript,function,Javascript,Function,我正在读道格拉斯·克罗克福德的书,他使用了 Function.method('inherits', function(Parent){ this.prototype=new Parent(); return this; }); 如果我们不考虑它的含义,我就无法绕开语法。我试着在chrome上运行它,然后 Uncaught TypeError: undefined is not a function test3.html:18 (anonymous function) 如果我尝试(

我正在读道格拉斯·克罗克福德的书,他使用了

Function.method('inherits', function(Parent){
   this.prototype=new Parent();
   return this;
});
如果我们不考虑它的含义,我就无法绕开语法。我试着在chrome上运行它,然后

Uncaught TypeError: undefined is not a function test3.html:18
(anonymous function)
如果我尝试()也会发生这种情况


似乎有人说这条线在工作,但我不能让它工作。为什么会这样?

生产线工作的原因是因为
功能。原型已通过以下方法扩展:

Function.prototype.method = function (name, func) {
   this.prototype[name] = func;
   return this;
};
如果您运行上述代码,然后才运行您拥有的代码,那么一切都将正常工作-或者您可以将
.method
更改为
.prototype[name\u here]=
,一切都将正常工作

关于最佳做法的说明
如果您打算在此日期扩展原型,最好使用它来确保该方法不可枚举。

该行工作的原因是因为
函数。原型已使用该方法扩展:

Function.prototype.method = function (name, func) {
   this.prototype[name] = func;
   return this;
};
如果您运行上述代码,然后才运行您拥有的代码,那么一切都将正常工作-或者您可以将
.method
更改为
.prototype[name\u here]=
,一切都将正常工作

关于最佳做法的说明
如果您打算在这个时代扩展原型,最好使用它来确保该方法不可枚举。

函数。method
不是内置的JavaScript函数。这是他编造的:
Function.method
不是内置的JavaScript函数。这是他编造的: