Skip to content

Instantly share code, notes, and snippets.

@shikelong
Created June 29, 2020 06:24
Show Gist options
  • Save shikelong/03fcd2cf9c170fe23fab619b289e8ce1 to your computer and use it in GitHub Desktop.
Save shikelong/03fcd2cf9c170fe23fab619b289e8ce1 to your computer and use it in GitHub Desktop.
JavaScript Simple Polyfill
//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