Skip to content

Instantly share code, notes, and snippets.

@matthewp
Last active January 1, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewp/8175510 to your computer and use it in GitHub Desktop.
Save matthewp/8175510 to your computer and use it in GitHub Desktop.
object.is is a polyfill for the es6 egal function: http://wiki.ecmascript.org/doku.php?id=harmony:egal
module.exports = Object.is || 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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment