mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Allow argCount to be omitted an not default to 3, and cleanup createBound.
Former-commit-id: cbafeaa441aae1ef28268bc2614b1a6e038acfe1
This commit is contained in:
83
dist/lodash.compat.js
vendored
83
dist/lodash.compat.js
vendored
@@ -482,7 +482,6 @@
|
||||
/** Native method shortcuts */
|
||||
var ceil = Math.ceil,
|
||||
clearTimeout = context.clearTimeout,
|
||||
concat = arrayRef.concat,
|
||||
defineProperty = reNative.test(defineProperty = Object.defineProperty) && defineProperty,
|
||||
floor = Math.floor,
|
||||
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
@@ -491,7 +490,8 @@
|
||||
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
||||
setImmediate = context.setImmediate,
|
||||
setTimeout = context.setTimeout,
|
||||
toString = objectProto.toString;
|
||||
toString = objectProto.toString,
|
||||
unshift = arrayRef.unshift;
|
||||
|
||||
/* Native method shortcuts for methods with the same name as other `lodash` methods */
|
||||
var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind,
|
||||
@@ -933,7 +933,7 @@
|
||||
/** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
|
||||
var eachIteratorOptions = {
|
||||
'args': 'collection, callback, thisArg',
|
||||
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg)",
|
||||
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg, 3)",
|
||||
'array': "typeof length == 'number'",
|
||||
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
|
||||
};
|
||||
@@ -1372,16 +1372,12 @@
|
||||
if (!isFunc && !isBindKey) {
|
||||
throw new TypeError;
|
||||
}
|
||||
var key = thisArg;
|
||||
|
||||
// juggle arguments for `_.bindKey` behavior
|
||||
if (isBindKey) {
|
||||
thisArg = func;
|
||||
}
|
||||
// use `Function#bind` if it exists and is fast
|
||||
// (in V8 `Function#bind` is slower except when partially applied)
|
||||
if (!isPartial && !isAlt && !partialRightArgs.length && (support.fastBind || (nativeBind && partialArgs.length))) {
|
||||
var bound = nativeBind.call.apply(nativeBind, concat.call(arrayRef, func, thisArg, partialArgs));
|
||||
args = [func, thisArg];
|
||||
push.apply(args, partialArgs);
|
||||
var bound = nativeBind.call.apply(nativeBind, args);
|
||||
}
|
||||
else {
|
||||
bound = function() {
|
||||
@@ -1394,7 +1390,7 @@
|
||||
func = thisArg[key];
|
||||
}
|
||||
if (partialArgs.length || partialRightArgs.length) {
|
||||
args = concat.apply(partialArgs, args);
|
||||
unshift.apply(args, partialArgs);
|
||||
push.apply(args, partialRightArgs);
|
||||
}
|
||||
if (this instanceof bound) {
|
||||
@@ -1409,6 +1405,10 @@
|
||||
return func.apply(thisBinding, args);
|
||||
};
|
||||
}
|
||||
if (isBindKey) {
|
||||
var key = thisArg;
|
||||
thisArg = func;
|
||||
}
|
||||
return bound;
|
||||
}
|
||||
|
||||
@@ -1891,7 +1891,7 @@
|
||||
*/
|
||||
function findKey(object, callback, thisArg) {
|
||||
var result;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
forOwn(object, function(value, key, object) {
|
||||
if (callback(value, key, object)) {
|
||||
result = key;
|
||||
@@ -2513,7 +2513,7 @@
|
||||
result = {};
|
||||
|
||||
if (isFunc) {
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
} else {
|
||||
var props = baseFlatten(arguments, true, false, 1);
|
||||
}
|
||||
@@ -2595,7 +2595,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
forIn(object, function(value, key, object) {
|
||||
if (callback(value, key, object)) {
|
||||
result[key] = value;
|
||||
@@ -2803,7 +2803,7 @@
|
||||
*/
|
||||
function countBy(collection, callback, thisArg) {
|
||||
var result = {};
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
forEach(collection, function(value, key, collection) {
|
||||
key = String(callback(value, key, collection));
|
||||
@@ -2855,7 +2855,7 @@
|
||||
*/
|
||||
function every(collection, callback, thisArg) {
|
||||
var result = true;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -2916,7 +2916,7 @@
|
||||
*/
|
||||
function filter(collection, callback, thisArg) {
|
||||
var result = [];
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -2982,7 +2982,7 @@
|
||||
* // => { 'name': 'banana', 'organic': true, 'type': 'fruit' }
|
||||
*/
|
||||
function find(collection, callback, thisArg) {
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -3080,7 +3080,7 @@
|
||||
*/
|
||||
function groupBy(collection, callback, thisArg) {
|
||||
var result = {};
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
forEach(collection, function(value, key, collection) {
|
||||
key = String(callback(value, key, collection));
|
||||
@@ -3168,7 +3168,7 @@
|
||||
length = collection ? collection.length : 0,
|
||||
result = Array(typeof length == 'number' ? length : 0);
|
||||
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
if (isArray(collection)) {
|
||||
while (++index < length) {
|
||||
result[index] = callback(collection[index], index, collection);
|
||||
@@ -3237,7 +3237,7 @@
|
||||
} else {
|
||||
callback = (!callback && isString(collection))
|
||||
? charAtCallback
|
||||
: lodash.createCallback(callback, thisArg);
|
||||
: lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
var current = callback(value, index, collection);
|
||||
@@ -3306,7 +3306,7 @@
|
||||
} else {
|
||||
callback = (!callback && isString(collection))
|
||||
? charAtCallback
|
||||
: lodash.createCallback(callback, thisArg);
|
||||
: lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
var current = callback(value, index, collection);
|
||||
@@ -3475,7 +3475,7 @@
|
||||
* // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }]
|
||||
*/
|
||||
function reject(collection, callback, thisArg) {
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
return filter(collection, function(value, index, collection) {
|
||||
return !callback(value, index, collection);
|
||||
});
|
||||
@@ -3577,7 +3577,7 @@
|
||||
*/
|
||||
function some(collection, callback, thisArg) {
|
||||
var result;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -3636,7 +3636,7 @@
|
||||
length = collection ? collection.length : 0,
|
||||
result = Array(typeof length == 'number' ? length : 0);
|
||||
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
forEach(collection, function(value, key, collection) {
|
||||
var object = result[++index] = getObject();
|
||||
object.criteria = callback(value, key, collection);
|
||||
@@ -3802,7 +3802,7 @@
|
||||
var index = -1,
|
||||
length = array ? array.length : 0;
|
||||
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
while (++index < length) {
|
||||
if (callback(array[index], index, array)) {
|
||||
return index;
|
||||
@@ -3875,7 +3875,7 @@
|
||||
|
||||
if (typeof callback != 'number' && callback != null) {
|
||||
var index = -1;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
while (++index < length && callback(array[index], index, array)) {
|
||||
n++;
|
||||
}
|
||||
@@ -4043,7 +4043,7 @@
|
||||
|
||||
if (typeof callback != 'number' && callback != null) {
|
||||
var index = length;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
while (index-- && callback(array[index], index, array)) {
|
||||
n++;
|
||||
}
|
||||
@@ -4176,7 +4176,7 @@
|
||||
|
||||
if (typeof callback != 'number' && callback != null) {
|
||||
var index = length;
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
while (index-- && callback(array[index], index, array)) {
|
||||
n++;
|
||||
}
|
||||
@@ -4336,7 +4336,7 @@
|
||||
index = -1,
|
||||
length = array ? array.length : 0;
|
||||
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
while (++index < length && callback(array[index], index, array)) {
|
||||
n++;
|
||||
}
|
||||
@@ -4480,7 +4480,7 @@
|
||||
isSorted = false;
|
||||
}
|
||||
if (callback != null) {
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg, 3);
|
||||
}
|
||||
return baseUniq(array, isSorted, callback);
|
||||
}
|
||||
@@ -4740,7 +4740,7 @@
|
||||
* @category Functions
|
||||
* @param {Mixed} [func=identity] The value to convert to a callback.
|
||||
* @param {Mixed} [thisArg] The `this` binding of the created callback.
|
||||
* @param {Number} [argCount=3] The number of arguments the callback accepts.
|
||||
* @param {Number} [argCount] The number of arguments the callback accepts.
|
||||
* @returns {Function} Returns a callback function.
|
||||
* @example
|
||||
*
|
||||
@@ -4813,23 +4813,22 @@
|
||||
if (typeof thisArg == 'undefined') {
|
||||
return func;
|
||||
}
|
||||
if (argCount === 1) {
|
||||
return function(value) {
|
||||
switch (argCount) {
|
||||
case 1: return function(value) {
|
||||
return func.call(thisArg, value);
|
||||
};
|
||||
}
|
||||
if (argCount === 2) {
|
||||
return function(a, b) {
|
||||
case 2: return function(a, b) {
|
||||
return func.call(thisArg, a, b);
|
||||
};
|
||||
}
|
||||
if (argCount === 4) {
|
||||
return function(accumulator, value, index, collection) {
|
||||
case 3: return function(value, index, collection) {
|
||||
return func.call(thisArg, value, index, collection);
|
||||
};
|
||||
case 4: return function(accumulator, value, index, collection) {
|
||||
return func.call(thisArg, accumulator, value, index, collection);
|
||||
};
|
||||
}
|
||||
return function(value, index, collection) {
|
||||
return func.call(thisArg, value, index, collection);
|
||||
return function() {
|
||||
return func.apply(thisArg, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user