Simplify _.mixin and _.wrap.

Former-commit-id: 89b802a1b887fcd61af8938e84f3ff06e3a7938c
This commit is contained in:
John-David Dalton
2012-10-23 09:03:56 -07:00
parent 442f51224d
commit 71fe13b249
3 changed files with 47 additions and 49 deletions

View File

@@ -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);