Permalink
Browse files

Fix #12107. Let .proxy() curry args without overwriting context. Close

  • Loading branch information...
1 parent cafb542 commit de9ff7cd171ebb47954ad95d50d2e41a49a7bfd2 Marcel Greter committed with dmethvin Jul 19, 2012
Showing with 10 additions and 2 deletions.
  1. +1 −1 src/core.js
  2. +9 −1 test/unit/core.js
View
@@ -765,7 +765,7 @@ jQuery.extend({
// Simulated bind
args = core_slice.call( arguments, 2 );
proxy = function() {
- return fn.apply( context, args.concat( core_slice.call( arguments ) ) );
+ return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
};
// Set the guid of unique handler to the same of original handler, so it can be removed
View
@@ -1057,7 +1057,7 @@ test("jQuery.isEmptyObject", function(){
});
test("jQuery.proxy", function(){
- expect(7);
+ expect( 9 );
var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
var thisObject = { foo: "bar", method: test };
@@ -1085,6 +1085,14 @@ test("jQuery.proxy", function(){
// Test old syntax
var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" );
+
+ // jQuery 1.9 improved currying with `this` object
+ var fn = function() {
+ equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
+ equal( this.foo, "bar", "this-object passed" );
+ };
+ var cb = jQuery.proxy( fn, null, "arg1", "arg2" );
+ cb.call( thisObject, "arg3" );
});
test("jQuery.parseHTML", function() {

0 comments on commit de9ff7c

Please sign in to comment.