Created
May 5, 2016 17:30
-
-
Save jugglinmike/66281aa3acb610d8db8c4bfe665a0a01 to your computer and use it in GitHub Desktop.
Object.reallyIs
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
/** | |
* 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