Skip to content

Commit

Permalink
added: Backcompatibility with old proxy syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
gf3 committed Jan 21, 2011
1 parent a03f040 commit 574ae3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core.js
Expand Up @@ -739,6 +739,12 @@ jQuery.extend({
proxy: function( fn, context ) {
var args, proxy;

// XXX BACKCOMPAT: Support old string method.
if ( typeof context === "string" ) {
fn = fn[ context ];
context = arguments[0];
}

// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( ! jQuery.isFunction( fn ) ) {
Expand Down
6 changes: 5 additions & 1 deletion test/unit/core.js
Expand Up @@ -869,7 +869,7 @@ test("jQuery.isEmptyObject", function(){
});

test("jQuery.proxy", function(){
expect(5);
expect(6);

var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); };
var thisObject = { foo: "bar", method: test };
Expand All @@ -890,6 +890,10 @@ test("jQuery.proxy", function(){
// Partial application w/ normal arguments
var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
jQuery.proxy( test3, null, "pre-applied" )( "normal" );

// Test old syntax
var test4 = { meth: function( a ){ equals( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" );
});

test("jQuery.parseJSON", function(){
Expand Down

0 comments on commit 574ae3b

Please sign in to comment.