我读的书JavaScript中的很大一部分,有一个例子prototype [name]和prototype.name有什么区别?
Function.prototype.method = function(name, func){
this.prototype[name] = func;
// this.prototype.name = func;
return this;
};
Number.method("integer", function(){
return Math[this<0 ? "ceiling" : "floor"](this);
});
document.writeln((10/3).integer());
我想this.prototype [名] = FUNC;和this.prototype.name = func;是同样的事情,但似乎他们不是。
当我在Chrome浏览器中注释掉的语句,它显示一个错误
“遗漏的类型错误:未定义是不是一个函数”
那么,什么是错误的说法?它不是将func分配给名称吗?
由于
准相关:'ceil'不是'天花板'。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil –
嗨,我在Chrome上进行了测试,天花板和Ceil都在工作,但是仍然感谢 – user1888955