Ell*_*lle 8 javascript math prototype
我必须在这里遗漏一些东西,因为对我来说Math.prototype是不确定的.为什么是这样?我试着这样做:
Math.prototype.randomRange = function(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}
Run Code Online (Sandbox Code Playgroud)
但反而必须做这样的事情:
Math.randomRange = function(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}
Run Code Online (Sandbox Code Playgroud)
但这感觉不对.是我还是应该以另一种方式做这件事?如果这是一个愚蠢或重复的问题,我很抱歉,但我找不到任何搜索结果(当我搜索"Math.prototype"时出现了两个问题,这有点奇怪).
这些Math函数类似于其他OO语言中的类级函数.构造函数上没有原型对象; 没人(我知道)无论如何都使用构造函数.(你会对一个Math实例做什么?)
编辑 - 它已在评论中指出(我从未想过要检查我猜)这Math不是一个功能.键入Math()您的浏览器控制台,你会得到一个错误.