mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #12107. Let .proxy() curry args without overwriting context. Close gh-866.
This commit is contained in:
parent
cafb542da9
commit
de9ff7cd17
@ -765,7 +765,7 @@ jQuery.extend({
|
|||||||
// Simulated bind
|
// Simulated bind
|
||||||
args = core_slice.call( arguments, 2 );
|
args = core_slice.call( arguments, 2 );
|
||||||
proxy = function() {
|
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
|
// Set the guid of unique handler to the same of original handler, so it can be removed
|
||||||
|
@ -1057,7 +1057,7 @@ test("jQuery.isEmptyObject", function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.proxy", function(){
|
test("jQuery.proxy", function(){
|
||||||
expect(7);
|
expect( 9 );
|
||||||
|
|
||||||
var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
|
var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
|
||||||
var thisObject = { foo: "bar", method: test };
|
var thisObject = { foo: "bar", method: test };
|
||||||
@ -1085,6 +1085,14 @@ test("jQuery.proxy", function(){
|
|||||||
// Test old syntax
|
// Test old syntax
|
||||||
var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
|
var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
|
||||||
jQuery.proxy( test4, "meth" )( "boom" );
|
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() {
|
test("jQuery.parseHTML", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user