Permalink
Browse files

Issue #79. Correctly setting 'this' in '_.wrap'

  • Loading branch information...
1 parent 9a9f2a8 commit 3a113d2d886ade3f83e8e49bb144a877a939062e @jashkenas jashkenas committed Dec 13, 2010
Showing with 6 additions and 1 deletion.
  1. +5 −0 test/functions.js
  2. +1 −1 underscore.js
View
@@ -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() {
View
@@ -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);
};
};

0 comments on commit 3a113d2

Please sign in to comment.