我在台式机野生动物园中使用javascript时遇到了一些问题,在移动设备上工作正常。
当我尝试运行时:
return Math.trunc(num * Math.pow(10, 2)) / Math.pow(10, 2);
我正在控制台上:
TypeError: 'undefined' is not a function (evaluating 'Math.trunc(num * Math.pow(10, 2))')
知道为什么会这样吗?在其余的浏览器上运行正常,我不知道为什么(我从未使用过野生动物园)。
Math.trunc
已在ES2015中添加(2015年6月)。显然您正在使用的Safari版本中的JavaScript引擎还没有它。
如果缺少它,可以填充它:
if (!Math.trunc) {
Object.defineProperty(Math, "trunc", {
value: function(val) {
return val < 0 ? Math.ceil(val) : Math.floor(val);
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句