Thursday, March 5, 2009

Using Function.createCallback with Function.createDelegate

In my earlier posts, I had described the functionalities of both Function.createCallback and Function.createDelegate. Basically, Function.createCallback can be used to pass extra data to the callback method (in the form of context) and Function.createDelegate creates wrapper function which in-turn calls the callback method as a part of the object instance passed to the createDelegate function.

But, what can we do, if we need both the functionalities? Well, basic logics says simply join both the functions. So, an affecting callback would be:

var callback = Function.createDelegate(this, Function.createCallback(this.callbackMethod, { id: id }));

$addHandler($get(‘TestElement’), ‘click’, callback);


No comments:

Post a Comment