diff --git a/CHANGELOG b/CHANGELOG index 889f9b0..390dc15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ -* Further fix to ensure Object#is(String|Number) do not throw exceptions on host objects in IE. (grepmaster, kangax, Tobie Langel, Andrew Dupont) +* Switch Object.is(Array|String|Number) to use the vastly-superior approach discovered by Juriy. (kangax) + +* Further fix to ensure Object.is(String|Number) do not throw exceptions on host objects in IE. (grepmaster, kangax, Tobie Langel, Andrew Dupont) * Ensure Enumerable#grep can handle strings with RegExp metacharacters. (Marton Kiss-Albert, kangax) diff --git a/src/lang/object.js b/src/lang/object.js index 19be092..f99004d 100644 --- a/src/lang/object.js +++ b/src/lang/object.js @@ -1,4 +1,10 @@ (function() { + + function getClass(object) { + return Object.prototype.toString.call(object) + .match(/^\[object\s(.*)\]$/)[1]; + } + function extend(destination, source) { for (var property in source) destination[property] = source[property]; @@ -70,8 +76,7 @@ } function isArray(object) { - return object != null && typeof object === "object" && - 'splice' in object && 'join' in object; + return getClass(object) === "Array"; } function isHash(object) { @@ -83,19 +88,11 @@ } function isString(object) { - try { - return typeof (object && object.valueOf()) === "string"; - } catch(e) { - return false; - } + return getClass(object) === "String"; } function isNumber(object) { - try { - return typeof (object && object.valueOf()) === "number"; - } catch(e) { - return false; - } + return getClass(object) === "Number"; } function isUndefined(object) {