Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 5, 2016 17:30
Show Gist options
  • Save jugglinmike/66281aa3acb610d8db8c4bfe665a0a01 to your computer and use it in GitHub Desktop.
Save jugglinmike/66281aa3acb610d8db8c4bfe665a0a01 to your computer and use it in GitHub Desktop.
Object.reallyIs
/**
* An extension of ES2015 `Object.is` that distinguishes between NaN values.
*/
(function() {
var full = new Float64Array(2);
var bytes = new Uint8Array(full.buffer);
Object.reallyIs = function(a, b) {
if (!Object.is(a, b)) {
return false;
}
if (!Object.is(a, NaN)) {
return true;
}
full[0] = a;
full[0] = b;
return bytes[0] === bytes[8] &&
bytes[1] === bytes[9] &&
bytes[2] === bytes[10] &&
bytes[3] === bytes[11] &&
bytes[4] === bytes[12] &&
bytes[5] === bytes[13] &&
bytes[6] === bytes[14] &&
bytes[7] === bytes[15];
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment