Skip to content

Commit de9ff7c

Browse files
Marcel Greterdmethvin
authored andcommitted
Fix #12107. Let .proxy() curry args without overwriting context. Close gh-866.
1 parent cafb542 commit de9ff7c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ jQuery.extend({
765765
// Simulated bind
766766
args = core_slice.call( arguments, 2 );
767767
proxy = function() {
768-
return fn.apply( context, args.concat( core_slice.call( arguments ) ) );
768+
return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
769769
};
770770

771771
// Set the guid of unique handler to the same of original handler, so it can be removed

test/unit/core.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ test("jQuery.isEmptyObject", function(){
10571057
});
10581058

10591059
test("jQuery.proxy", function(){
1060-
expect(7);
1060+
expect( 9 );
10611061

10621062
var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
10631063
var thisObject = { foo: "bar", method: test };
@@ -1085,6 +1085,14 @@ test("jQuery.proxy", function(){
10851085
// Test old syntax
10861086
var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
10871087
jQuery.proxy( test4, "meth" )( "boom" );
1088+
1089+
// jQuery 1.9 improved currying with `this` object
1090+
var fn = function() {
1091+
equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
1092+
equal( this.foo, "bar", "this-object passed" );
1093+
};
1094+
var cb = jQuery.proxy( fn, null, "arg1", "arg2" );
1095+
cb.call( thisObject, "arg3" );
10881096
});
10891097

10901098
test("jQuery.parseHTML", function() {

0 commit comments

Comments
 (0)