我正在閱讀javascripts的好的部分,並測試了一個代碼。添加一個方法來數字拋出異常
Number.method('integer', function () {
\t document.writeln("called"+ this<0);
return Math[this < 0 ? 'ceiling' : 'floor'](this);
});
,並通過調用它測試它作爲
document.writeln((-10/3).integer());
我得到Uncaught TypeError: Math[(intermediate value)(intermediate value)(intermediate value)] is not a function
錯誤。難道我做錯了什麼?我對鉻
我忘了提及測試它,還有另一種方法添加到function.protoype作爲
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
只是一個小提示:在2016年有什麼理由用'文件撰寫...'調用調試。請了解控制檯及其API:'console.log()'等。 –