Math API polyfill 改写为长尾,可以这样表达:如何实现一个兼容多种浏览器的 Math 对象 polyfill?
- 内容介绍
- 文章标签
- 相关推荐
本文共计104个文字,预计阅读时间需要1分钟。
javascriptMath.trunc=Math.trunc || function(x) { return x <0 ? Math.ceil(x) : Math.floor(x);};
Math.sign=Math.sign || function(x) { x=+x; if (x===0 || isNaN(x)) { return x; } return x <0 ? -1 : 1;};
Math.truncMath.trunc = Math.trunc || function(x) { return x < 0 ? Math.ceil(x) : Math.floor(x); } Math.sign = Math.sign || function(x) { x = +x; // convert to number if (x === 0 || isNaN(x)) { return x; } return x > 0 ? 1 : -1; } Math.cbrt = Math.cbrt || function(x) { var y = Math.pow(Math.abs(x), 1/3); return x < 0 ? -y : y; }
本文共计104个文字,预计阅读时间需要1分钟。
javascriptMath.trunc=Math.trunc || function(x) { return x <0 ? Math.ceil(x) : Math.floor(x);};
Math.sign=Math.sign || function(x) { x=+x; if (x===0 || isNaN(x)) { return x; } return x <0 ? -1 : 1;};
Math.truncMath.trunc = Math.trunc || function(x) { return x < 0 ? Math.ceil(x) : Math.floor(x); } Math.sign = Math.sign || function(x) { x = +x; // convert to number if (x === 0 || isNaN(x)) { return x; } return x > 0 ? 1 : -1; } Math.cbrt = Math.cbrt || function(x) { var y = Math.pow(Math.abs(x), 1/3); return x < 0 ? -y : y; }

