我一直在阅读"javascript:好的部分".
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Run Code Online (Sandbox Code Playgroud)
示例用法是:
Number.method('integer', function () {
return Math[this < 0 ? 'ceiling' : 'floor'](this);
});
document.writeln((-10 / 3).integer()); // -3
Run Code Online (Sandbox Code Playgroud)
两个问题:
"通过使用方法方法扩充Function.prototype ,我们不再需要输入原型属性的名称.现在可以隐藏这一点丑陋." 那是什么意思?所以它节省了输入".prototype.integer"?似乎并不重要.
我们进行了扩充Function.prototype,这听起来是功能特有的.Number是本机类型,我们应该增加Object.prototype吗?