Number.isNaN
// window.isNaN('a') true
if(!Number.isNaN) {
Number.isNaN = function(n) {
return (
typeof n === 'number' &&
window.isNaN(n)
)
}
}
复制代码
object.is = function(v1, v2) {
// 0 === -0 Infinity !== -Infinity
if (v1 === 0 && v2 === 0) {
retuen 1 / v1 === 1 / v2;
}
// NaN !== NaN
if (v2 !== v2) {
return v2 !== v2;
}
return v1 === v2;
}
复制代码
Date.now
// +new Date() ==== +new Date === new Date().getTime()
if(!Date.now) {
Date.now = function() {
return +new Date();
}
}
复制代码
转载于:https://juejin.im/post/5b9b7c4fe51d450e84779255