Switch Object.is(Array|String|Number) to use the vastly-superior approach discovered by Juriy.

This commit is contained in:
Andrew Dupont 2009-01-11 18:26:26 -06:00
parent 31d1c6fd48
commit 997689fcea
2 changed files with 12 additions and 13 deletions

View File

@ -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)

View File

@ -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) {