Nothing special, ternary operator version of: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Polyfill
-
-
Save yckart/683a29105645c8b75396 to your computer and use it in GitHub Desktop.
Polyfill for "Object.is" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Polyfill
This file contains 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
Object.is || (Object.is = function (a, b) { | |
return | |
/* if */(a === 0 && b === 0) ? | |
(1 / a === 1 / b) : | |
/* else if */(a !== a) ? | |
(b !== b) : | |
/* else */ | |
(a === b); | |
}); |
This file contains 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
Object.is||(Object.is=function(a,b){return a===0&&b===0?1/a===1/b:a!==a?b!==b:a===b}); |
This file contains 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2015 Yannick Albert <http://yannick-albert.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains 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
{ | |
"name": "ObjectIsPolyfill", | |
"description": "Polyfill for Object.is", | |
"keywords": [ | |
"strict", | |
"equal", | |
"object", | |
"is", | |
"compare" | |
] | |
} |
This file contains 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
<!DOCTYPE html> | |
<title>Object.is polyfill | 140byt.es</title> | |
<p>I'm too lazy right now. Take a look at the gist.</p> | |
<script> | |
Object.is || Object.is = function(a,b){return a===0&&b===0?1/a===1/b:a!==a?b!==b:a===b}; | |
Object.is('foo', 'foo'); // true | |
Object.is(window, window); // true | |
Object.is('foo', 'bar'); // false | |
Object.is([], []); // false | |
var test = { a: 1 }; | |
Object.is(test, test); // true | |
Object.is(null, null); // true | |
// Special Cases | |
Object.is(0, -0); // false | |
Object.is(-0, -0); // true | |
Object.is(NaN, 0/0); // true | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@atk Whoops, lost
b
by killing some noise. It's somewhere on my desk now, give me a minute ;)It's not that great, those inbuild things, but I've to accept...