mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Merge pull request #410 from foobarfighter/wrap-bug-fix
Fixes #409 - Unexpected arguments passed to wrapper function in _.wrap when the first argument of calling the wrapped function is an array
This commit is contained in:
@@ -163,6 +163,11 @@ $(document).ready(function() {
|
|||||||
var obj = {name : "Moe"};
|
var obj = {name : "Moe"};
|
||||||
obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; });
|
obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; });
|
||||||
equals(obj.hi(), "Hello Moe");
|
equals(obj.hi(), "Hello Moe");
|
||||||
|
|
||||||
|
var noop = function(){};
|
||||||
|
var wrapped = _.wrap(noop, function(fn){ return Array.prototype.slice.call(arguments, 0); });
|
||||||
|
var ret = wrapped(['whats', 'your'], 'vector', 'victor');
|
||||||
|
same(ret, [noop, ['whats', 'your'], 'vector', 'victor']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("functions: compose", function() {
|
test("functions: compose", function() {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
// Create quick reference variables for speed access to core prototypes.
|
// Create quick reference variables for speed access to core prototypes.
|
||||||
var slice = ArrayProto.slice,
|
var slice = ArrayProto.slice,
|
||||||
concat = ArrayProto.concat,
|
|
||||||
unshift = ArrayProto.unshift,
|
unshift = ArrayProto.unshift,
|
||||||
toString = ObjProto.toString,
|
toString = ObjProto.toString,
|
||||||
hasOwnProperty = ObjProto.hasOwnProperty;
|
hasOwnProperty = ObjProto.hasOwnProperty;
|
||||||
@@ -584,7 +583,7 @@
|
|||||||
// conditionally execute the original function.
|
// conditionally execute the original function.
|
||||||
_.wrap = function(func, wrapper) {
|
_.wrap = function(func, wrapper) {
|
||||||
return function() {
|
return function() {
|
||||||
var args = concat.apply([func], arguments);
|
var args = [func].concat(slice.call(arguments, 0));
|
||||||
return wrapper.apply(this, args);
|
return wrapper.apply(this, args);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user