Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试扩充javascript中的内置类型时出错_Javascript - Fatal编程技术网

尝试扩充javascript中的内置类型时出错

尝试扩充javascript中的内置类型时出错,javascript,Javascript,我正在尝试使用我的HTML页面的脚本标记中的以下代码来扩充javascript的内置Number数据类型: Number.method('integer', function () { return Math[this < 0 ? 'ceiling' : 'floor'](this); }); document.writeln((-10 / 3).integer( )); Number.method('integer',function

我正在尝试使用我的HTML页面的脚本标记中的以下代码来扩充javascript的内置
Number
数据类型:

 Number.method('integer', function () {
        return Math[this < 0 ? 'ceiling' : 'floor'](this);
        });
        document.writeln((-10 / 3).integer( )); 
Number.method('integer',function(){
返回数学[this<0?“天花板”:“地板](this);
});
document.writeln(-10/3).integer());
在浏览器中浏览页面时,开发人员工具会报告以下错误:

未捕获类型错误:Number.method不是函数
在test.html:10 (匿名)@test.html:10

浏览器信息:谷歌浏览器

我无法识别代码中的错误。有人能帮我吗?

是的,您必须定义并使用而不是
天花板

Function.prototype.method=函数(名称,func){
this.prototype[name]=func;
归还这个;
};
Number.method('integer',function(){
返回数学[this<0?'ceil':'floor'](this);
});

log(-10/3.integer())
是否不必对内置的“对象”使用
prototype
?我已经尝试了该选项,但随后错误只会更改为-
Uncaught TypeError:Number.prototype.method不是函数
此主题有帮助吗?我以前没有听说过
方法
函数。我也没有看到关于它的任何文档。你到底想干什么?谢谢。我没有为
函数
的原型添加
方法
扩展<代码>天花板
是一个印刷错误,我相信我现在指的是这本书本身。抢手货