mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Ensure correct execution order of _.modArgs transforms.
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -3527,13 +3527,16 @@
|
|||||||
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
var length = transforms.length;
|
var funcsLength = transforms.length;
|
||||||
return restParam(function(args) {
|
return restParam(function(args) {
|
||||||
var index = nativeMin(args.length, length);
|
var index = -1,
|
||||||
while (index--) {
|
length = nativeMin(args.length, funcsLength),
|
||||||
args[index] = transforms[index].apply(this, resolver(args[index], index, args));
|
modded = copyArray(args);
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
modded[index] = transforms[index].apply(this, resolver(args[index], index, args));
|
||||||
}
|
}
|
||||||
return func.apply(this, args);
|
return func.apply(this, modded);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11120,6 +11120,15 @@
|
|||||||
deepEqual(modded(5), [10]);
|
deepEqual(modded(5), [10]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should provide the correct argument to each transform', 1, function() {
|
||||||
|
var argsList = [],
|
||||||
|
transform = function() { argsList.push(slice.call(arguments)); },
|
||||||
|
modded = _.modArgs(_.noop, transform, transform, transform);
|
||||||
|
|
||||||
|
modded('a', 'b', 'c');
|
||||||
|
deepEqual(argsList, [['a'], ['b'], ['c']]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should use `this` binding of function for transforms', 1, function() {
|
test('should use `this` binding of function for transforms', 1, function() {
|
||||||
var modded = _.modArgs(function(x) {
|
var modded = _.modArgs(function(x) {
|
||||||
return this[x];
|
return this[x];
|
||||||
|
|||||||
Reference in New Issue
Block a user