mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Remove thisArg from _.spread. [closes #957]
This commit is contained in:
@@ -7643,15 +7643,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that invokes `func` with the `this` binding of `thisArg`
|
* Creates a function that invokes `func` with the `this` binding of the
|
||||||
* and the array of arguments provided to the created function much like
|
* created function and the array of arguments provided to the created
|
||||||
* [Function#apply](http://es5.github.io/#x15.3.4.3).
|
* function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Function
|
* @category Function
|
||||||
* @param {Function} The function to spread arguments over.
|
* @param {Function} The function to spread arguments over.
|
||||||
* @param {*} [thisArg] The `this` binding of `func`.
|
|
||||||
* @returns {*} Returns the new function.
|
* @returns {*} Returns the new function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -7680,7 +7679,7 @@
|
|||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
return function(array) {
|
return function(array) {
|
||||||
return func.apply(thisArg, array);
|
return func.apply(this, array);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
test/test.js
11
test/test.js
@@ -12446,10 +12446,6 @@
|
|||||||
QUnit.module('lodash.spread');
|
QUnit.module('lodash.spread');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
function add(x, y) {
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
|
|
||||||
test('should spread arguments to `func`', 1, function() {
|
test('should spread arguments to `func`', 1, function() {
|
||||||
var spread = _.spread(add);
|
var spread = _.spread(add);
|
||||||
strictEqual(spread([4, 2]), 6);
|
strictEqual(spread([4, 2]), 6);
|
||||||
@@ -12470,12 +12466,13 @@
|
|||||||
deepEqual(args, [4, 2]);
|
deepEqual(args, [4, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should support the `thisArg` argument', 1, function() {
|
test('should not set a `this` binding', 1, function() {
|
||||||
var spread = _.spread(function(x, y) {
|
var spread = _.spread(function(x, y) {
|
||||||
return this[x] + this[y];
|
return this[x] + this[y];
|
||||||
}, [4, 2]);
|
});
|
||||||
|
|
||||||
strictEqual(spread([0, 1]), 6);
|
var object = { 'spread': spread, 'x': 4, 'y': 2 };
|
||||||
|
strictEqual(object.spread(['x', 'y']), 6);
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user