PDA

View Full Version : createCallback and createDelegate



Nisse
28 Jan 2008, 1:17 AM
Hi could someone please briefly explain how the createCallback and createDelegate functions work? I know these are powerful concepts and I know how to use the pre-defined ones in Ext but I don't know how to create my own using the two functions above. I've looked at the help and the Ext.js but I'm still lost on this.

Thanks,
Nisse

evant
28 Jan 2008, 1:45 AM
They are similar things. Basically, they allow you to bind a handler and also controlling the parameters (and the scope for createDelegate).

For example:



var a = new Ext.Button(
{
...
handler: myFunc.createDelegate(someScope, ['some', 'custom', 'params', 1])
}
);

var b = new Ext.Button(
{
...
handler: myFunc
}
);


If you contrast the first with the second, you'll see that in the second you have no control of what parameters are passed, whereas with createDelegate you can control this, as well as the scope that the method will be executed in.