Optimize _.isArray fallback, _.isDate, _.isFunction, and _.isRegExp.

Former-commit-id: a3e350bf1fa91a9582ba6a0effe61d4589cc8afe
This commit is contained in:
John-David Dalton
2012-12-10 00:25:07 -08:00
parent 13d62b01d1
commit 0b48b9c7d4
5 changed files with 43 additions and 42 deletions

View File

@@ -908,7 +908,7 @@
* // => true
*/
var isArray = nativeIsArray || function(value) {
return toString.call(value) == arrayClass;
return value instanceof Array || toString.call(value) == arrayClass;
};
/**
@@ -942,7 +942,7 @@
* // => true
*/
function isDate(value) {
return toString.call(value) == dateClass;
return value instanceof Date || toString.call(value) == dateClass;
}
/**
@@ -1190,7 +1190,7 @@
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
return toString.call(value) == funcClass;
return value instanceof Function || toString.call(value) == funcClass;
};
}
@@ -1304,7 +1304,7 @@
* // => true
*/
function isRegExp(value) {
return toString.call(value) == regexpClass;
return value instanceof RegExp || toString.call(value) == regexpClass;
}
/**