diff --git a/src/core.js b/src/core.js index a9ad6bf6a..fa9899682 100644 --- a/src/core.js +++ b/src/core.js @@ -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 diff --git a/test/unit/core.js b/test/unit/core.js index 4c27f942f..2e386b0e8 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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() {