Created
June 29, 2020 06:24
-
-
Save shikelong/03fcd2cf9c170fe23fab619b289e8ce1 to your computer and use it in GitHub Desktop.
JavaScript Simple Polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//different with ==, object.is not implict convert | |
//object is 判断 NaN/+-0 相等行为和 === 不同 | |
if (!Object.is) { | |
Object.is = function(x, y) { | |
// SameValue algorithm | |
if (x === y) { // Steps 1-5, 7-10 | |
// Steps 6.b-6.e: +0 != -0 | |
return x !== 0 || 1 / x === 1 / y; | |
} else { | |
// Step 6.a: NaN == NaN | |
return x !== x && y !== y; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment