Make isArayLike return false for functions.

This commit is contained in:
John-David Dalton
2015-07-10 00:30:59 -07:00
parent 31a7ac1e81
commit 06bc4aa50b

View File

@@ -3010,11 +3010,14 @@
*/ */
function createBaseEach(eachFunc, fromRight) { function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) { return function(collection, iteratee) {
var length = collection ? getLength(collection) : 0; if (collection == null) {
if (!isLength(length)) { return collection;
}
if (!isArrayLike(collection)) {
return eachFunc(collection, iteratee); return eachFunc(collection, iteratee);
} }
var index = fromRight ? length : -1, var length = collection.length,
index = fromRight ? length : -1,
iterable = toObject(collection); iterable = toObject(collection);
while ((fromRight ? index-- : ++index < length)) { while ((fromRight ? index-- : ++index < length)) {
@@ -3833,7 +3836,7 @@
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
*/ */
function isArrayLike(value) { function isArrayLike(value) {
return value != null && isLength(getLength(value)); return value != null && typeof value != 'function' && isLength(getLength(value));
} }
/** /**
@@ -6157,11 +6160,8 @@
* // => true * // => true
*/ */
function includes(collection, target, fromIndex, guard) { function includes(collection, target, fromIndex, guard) {
var length = collection ? getLength(collection) : 0; collection = isArrayLike(collection) ? collection : values(collection);
if (!isLength(length)) { var length = collection.length;
collection = values(collection);
length = collection.length;
}
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) { if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
fromIndex = 0; fromIndex = 0;
} else { } else {
@@ -8492,11 +8492,10 @@
* // => [2, 3] * // => [2, 3]
*/ */
function toArray(value) { function toArray(value) {
var length = value ? getLength(value) : 0; if (!isArrayLike(value)) {
if (!isLength(length)) {
return values(value); return values(value);
} }
if (!length) { if (!value.length) {
return []; return [];
} }
return (lodash.support.unindexedChars && isString(value)) return (lodash.support.unindexedChars && isString(value))