mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Simplify _.mixin and _.wrap.
Former-commit-id: 89b802a1b887fcd61af8938e84f3ff06e3a7938c
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -3469,19 +3469,17 @@
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var hello = function(name) { return 'hello: ' + name; };
|
||||
* var hello = function(name) { return 'hello ' + name; };
|
||||
* hello = _.wrap(hello, function(func) {
|
||||
* return 'before, ' + func('moe') + ', after';
|
||||
* });
|
||||
* hello();
|
||||
* // => 'before, hello: moe, after'
|
||||
* // => 'before, hello moe, after'
|
||||
*/
|
||||
function wrap(value, wrapper) {
|
||||
return function() {
|
||||
var args = [value];
|
||||
if (arguments.length) {
|
||||
push.apply(args, arguments);
|
||||
}
|
||||
push.apply(args, arguments);
|
||||
return wrapper.apply(this, args);
|
||||
};
|
||||
}
|
||||
@@ -3554,9 +3552,8 @@
|
||||
|
||||
lodash.prototype[methodName] = function() {
|
||||
var args = [this.__wrapped__];
|
||||
if (arguments.length) {
|
||||
push.apply(args, arguments);
|
||||
}
|
||||
push.apply(args, arguments);
|
||||
|
||||
var result = func.apply(lodash, args);
|
||||
if (this.__chain__) {
|
||||
result = new lodash(result);
|
||||
|
||||
Reference in New Issue
Block a user