mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Clarify browsers affected by nonEnumArgs and reduce code around hasEnumPrototype.
Former-commit-id: 587f755332accbca26dc1eb357a66d4f898aad88
This commit is contained in:
29
lodash.js
29
lodash.js
@@ -85,7 +85,6 @@
|
||||
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
hasOwnProperty = objectRef.hasOwnProperty,
|
||||
push = arrayRef.push,
|
||||
propertyIsEnumerable = objectRef.propertyIsEnumerable,
|
||||
toString = objectRef.toString;
|
||||
|
||||
/* Native method shortcuts for methods with the same name as other `lodash` methods */
|
||||
@@ -153,7 +152,7 @@
|
||||
var hasObjectSpliceBug = (hasObjectSpliceBug = { '0': 1, 'length': 1 },
|
||||
arrayRef.splice.call(hasObjectSpliceBug, 0, 1), hasObjectSpliceBug[0]);
|
||||
|
||||
/** Detect if an `arguments` object's indexes are non-enumerable (IE < 9) */
|
||||
/** Detect if `arguments` object indexes are non-enumerable (Firefox < 4, IE < 9, Safari < 5.1) */
|
||||
var nonEnumArgs = true;
|
||||
|
||||
(function() {
|
||||
@@ -164,7 +163,7 @@
|
||||
for (prop in arguments) { nonEnumArgs = !prop; }
|
||||
|
||||
hasDontEnumBug = !/valueOf/.test(props);
|
||||
hasEnumPrototype = propertyIsEnumerable.call(ctor, 'prototype');
|
||||
hasEnumPrototype = ctor.propertyIsEnumerable('prototype');
|
||||
iteratesOwnLast = props[0] != 'x';
|
||||
}(1));
|
||||
|
||||
@@ -392,8 +391,7 @@
|
||||
|
||||
// avoid iterating over `prototype` properties in older Firefox, Opera, and Safari
|
||||
' <% if (hasEnumPrototype) { %>\n' +
|
||||
" var skipProto = typeof iterable == 'function' && \n" +
|
||||
" propertyIsEnumerable.call(iterable, 'prototype');\n" +
|
||||
" var skipProto = typeof iterable == 'function';\n" +
|
||||
' <% } %>' +
|
||||
|
||||
// iterate own properties using `Object.keys` if it's fast
|
||||
@@ -710,13 +708,13 @@
|
||||
// create the function factory
|
||||
var factory = Function(
|
||||
'createCallback, hasOwnProperty, isArguments, isArray, isString, ' +
|
||||
'objectTypes, nativeKeys, propertyIsEnumerable',
|
||||
'objectTypes, nativeKeys',
|
||||
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
|
||||
);
|
||||
// return the compiled function
|
||||
return factory(
|
||||
createCallback, hasOwnProperty, isArguments, isArray, isString,
|
||||
objectTypes, nativeKeys, propertyIsEnumerable
|
||||
objectTypes, nativeKeys
|
||||
);
|
||||
}
|
||||
|
||||
@@ -728,6 +726,7 @@
|
||||
* iteration early by explicitly returning `false`.
|
||||
*
|
||||
* @private
|
||||
* @type Function
|
||||
* @param {Array|Object|String} collection The collection to iterate over.
|
||||
* @param {Function} [callback=identity] The function called per iteration.
|
||||
* @param {Mixed} [thisArg] The `this` binding of `callback`.
|
||||
@@ -855,6 +854,7 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Objects
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} [callback=identity] The function called per iteration.
|
||||
@@ -887,6 +887,7 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Objects
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} [callback=identity] The function called per iteration.
|
||||
@@ -937,10 +938,14 @@
|
||||
* // => ['one', 'two', 'three'] (order is not guaranteed)
|
||||
*/
|
||||
var keys = !nativeKeys ? shimKeys : function(object) {
|
||||
// avoid iterating over the `prototype` property
|
||||
return hasEnumPrototype && typeof object == 'function' && propertyIsEnumerable.call(object, 'prototype')
|
||||
? shimKeys(object)
|
||||
: (isObject(object) ? nativeKeys(object) : []);
|
||||
if (!isObject(object)) {
|
||||
return [];
|
||||
}
|
||||
if ((hasEnumPrototype && typeof object == 'function') ||
|
||||
(nonEnumArgs && object.length && isArguments(object))) {
|
||||
return shimKeys(object);
|
||||
}
|
||||
return nativeKeys(object);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1027,6 +1032,7 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @alias extend
|
||||
* @category Objects
|
||||
* @param {Object} object The destination object.
|
||||
@@ -1220,6 +1226,7 @@
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Objects
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} [source1, source2, ...] The source objects.
|
||||
|
||||
Reference in New Issue
Block a user