/documentation/appframework/$.proxy.md
Markdown | 59 lines | 36 code | 23 blank | 0 comment | 0 complexity | 37da14395ce75e23cc599b61664b13ca MD5 | raw file
- #$.proxy(callback,context);
- ```
- Creates a proxy function so you can chane "this" context in the function
-
- ```
- ##Example
- ```
- var newObj={foo:bar}
- $("#main").bind("click",$.proxy(function(evt){console.log(this)},newObj);
- ( $.proxy(function(foo, bar){console.log(this+foo+bar)}, newObj) )("foo", "bar");
- ( $.proxy(function(foo, bar){console.log(this+foo+bar)}, newObj, ["foo", "bar"]) )();
-
- ```
- ##Parameters
- ```
- callback Function
- Context Object
- ```
- ##Returns
- ```
- undefined
- ```
- ##Detail
- $.proxy(callback,context) allows you to create a proxy function that changes the context of "this"
- There are times where you want "this" to be something other then the object that the event or function is dispatched on.
- ```
- var newObj={foo:bar}
- $("#main").bind("click",$.proxy(function(evt){console.log(this)},newObj);
- or
- ( $.proxy(function(foo, bar){console.log(this+foo+bar)}, newObj) )('foo', 'bar');
- or
- ( $.proxy(function(foo, bar){console.log(this+foo+bar)}, newObj, ['foo', 'bar']) )();
- ```
- Below we will have an anchor and proxy the click event so "this" is the object {foo:'bar'}
- ```
- var obj={foo:'bar'}
- $("#proxyTest").bind("click",$.proxy(function(){alert(this.foo);},obj));
- ```