私は Javascript を学んでいるので、この質問はほとんどの JS コーダーにとってばかげているように思えるかもしれません。私はJavascriptを読んでいます:良い部分ですが、このコードを機能させることはできません:
Function.prototype.method = function(name,func){
this.prototype[name] = func;
return this;
}
Number.method('integer', function(){
return Math[ this <0? 'ceiling' : 'floor'](this);
});
document.writeln(Math.floor(3.4)+"");
document.writeln((-10/3).integer());
おそらくご想像のとおり、最初の document.writeln 関数は本来あるべき "3" を表示しますが、2 番目の関数は何も表示せず、エラーは "TypeError: Math["floor"] is not a function" です。機能。
これはばかげていると確信していますが、なぜ機能しないのかわかりません。御時間ありがとうございます。
ファビアン