In jQuery API doc, the jQuery.proxy function usage:
jQuery.proxy( function, context )
function The function whose context will be changed.
context The object to which the context (this) of the function should be set.
jQuery.proxy( context, name )
context The object to which the context of the function should be set.
name The name of the function whose context will be changed (should be a property of the context object).
proxy : function(fn, proxy, thisObject){
if ( arguments.length === 2 ) {
if (typeof proxy === "string" ) {
thisObject = fn;
fn = thisObject[proxy];
proxy = undefined;
} else if ( proxy && !jQuery.isFunction( proxy ) ) {
thisObject = proxy;
proxy = undefined;
}
}
if ( !proxy && fn ) {
proxy = function() {
return fn.apply( thisObject || this, arguments );
};
}
// So proxy can be declared as an argument
return proxy;
}
But when I look into jQuery source code, of function proxy. I found there’re 3 parameters declared.
So I wonder what’s the use of third param, cannot understand the code 🙁
I write a code segment to test the function.
var someObj = { somefnc : function() {} };
function fnc() {
this.somefnc();
console.log(arguments);
}
var proxyedFnc = jQuery.proxy(fnc, undefined, someObj, "arg1","arg2");
proxyedFnc();
//output: []
And I wonder why the arguments were not passed to fnc..
Below is the source comes from jquery-1.7.2.js, Are you sure you check the same version between source and api doc?