Created
March 14, 2012 13:23
-
-
Save matthewp/2036428 to your computer and use it in GitHub Desktop.
Object.is polyfill
This file contains hidden or 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
// Blatantly stolen from ES6 specs. Kept here for reference. | |
// http://wiki.ecmascript.org/doku.php?id=harmony:egal | |
if(!Object.is) { | |
Object.defineProperty(Object, 'is', { | |
value: function(x, y) { | |
if (x === y) { | |
// 0 === -0, but they are not identical | |
return x !== 0 || 1 / x === 1 / y; | |
} | |
// NaN !== NaN, but they are identical. | |
// NaNs are the only non-reflexive value, i.e., if x !== x, | |
// then x is a NaN. | |
// isNaN is broken: it converts its argument to number, so | |
// isNaN("foo") => true | |
return x !== x && y !== y; | |
}, | |
configurable: true, | |
enumerable: false, | |
writable: true | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment