mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Issue #79. Correctly setting 'this' in '_.wrap'
This commit is contained in:
@@ -96,6 +96,11 @@ $(document).ready(function() {
|
||||
var greet = function(name){ return "hi: " + name; };
|
||||
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });
|
||||
equals(backwards('moe'), 'hi: moe eom', 'wrapped the saluation function');
|
||||
|
||||
var inner = function(){ return "Hello "; };
|
||||
var obj = {name : "Moe"};
|
||||
obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; });
|
||||
equals(obj.hi(), "Hello Moe");
|
||||
});
|
||||
|
||||
test("functions: compose", function() {
|
||||
|
||||
@@ -469,7 +469,7 @@
|
||||
_.wrap = function(func, wrapper) {
|
||||
return function() {
|
||||
var args = [func].concat(slice.call(arguments));
|
||||
return wrapper.apply(wrapper, args);
|
||||
return wrapper.apply(this, args);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user