Skip to content

Instantly share code, notes, and snippets.

@matthewp
Created March 14, 2012 13:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewp/2036428 to your computer and use it in GitHub Desktop.
Save matthewp/2036428 to your computer and use it in GitHub Desktop.
Object.is polyfill
// 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