mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Ensure isType methods return false for subclassed values.
Former-commit-id: e300d12eb506c6ae4949bd37cf8eb33c3a4be2e1
This commit is contained in:
49
lodash.js
49
lodash.js
@@ -943,6 +943,26 @@
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is an array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Objects
|
||||
* @param {Mixed} value The value to check.
|
||||
* @returns {Boolean} Returns `true`, if the `value` is an array, else `false`.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.isArray(arguments); })();
|
||||
* // => false
|
||||
*
|
||||
* _.isArray([1, 2, 3]);
|
||||
* // => true
|
||||
*/
|
||||
var isArray = nativeIsArray || function(value) {
|
||||
return value && typeof value == 'object' && toString.call(value) == arrayClass;
|
||||
};
|
||||
|
||||
/**
|
||||
* A fallback implementation of `Object.keys` which produces an array of the
|
||||
* given object's own enumerable property names.
|
||||
@@ -1416,29 +1436,6 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is an array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Objects
|
||||
* @param {Mixed} value The value to check.
|
||||
* @returns {Boolean} Returns `true`, if the `value` is an array, else `false`.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.isArray(arguments); })();
|
||||
* // => false
|
||||
*
|
||||
* _.isArray([1, 2, 3]);
|
||||
* // => true
|
||||
*/
|
||||
function isArray(value) {
|
||||
// `instanceof` may cause a memory leak in IE 7 if `value` is a host object
|
||||
// http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
|
||||
return (support.argsObject && value instanceof Array) ||
|
||||
(nativeIsArray ? nativeIsArray(value) : toString.call(value) == arrayClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is a boolean value.
|
||||
*
|
||||
@@ -1470,7 +1467,7 @@
|
||||
* // => true
|
||||
*/
|
||||
function isDate(value) {
|
||||
return value instanceof Date || toString.call(value) == dateClass;
|
||||
return value ? typeof value == 'object' && toString.call(value) == dateClass : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1774,7 +1771,7 @@
|
||||
// fallback for older versions of Chrome and Safari
|
||||
if (isFunction(/x/)) {
|
||||
isFunction = function(value) {
|
||||
return value instanceof Function || toString.call(value) == funcClass;
|
||||
return typeof value == 'function' && toString.call(value) == funcClass;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1924,7 +1921,7 @@
|
||||
* // => true
|
||||
*/
|
||||
function isRegExp(value) {
|
||||
return value instanceof RegExp || toString.call(value) == regexpClass;
|
||||
return value ? typeof value == 'object' && toString.call(value) == regexpClass : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user