From 3cf3410b512e4ab06d65f7ce8f1622402ba19bdb Mon Sep 17 00:00:00 2001 From: bigopon Date: Wed, 24 Jan 2018 16:22:52 +1100 Subject: [PATCH] feat(Object): add Object.is() (#58) --- src/object.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/object.js b/src/object.js index 386921a..3d83ac2 100644 --- a/src/object.js +++ b/src/object.js @@ -106,4 +106,21 @@ if (typeof FEATURE_NO_ES2015 === 'undefined') { }); }(Object)); +/** + * Object.is() polyfill + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +if (!Object.is) { + Object.is = function(x, y) { + // SameValue algorithm + if (x === y) { // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + return x !== 0 || 1 / x === 1 / y; + } else { + // Step 6.a: NaN == NaN + return x !== x && y !== y; + } + }; +} + } // endif FEATURE_NO_ES2015