PDA

View Full Version : Function parameter keeping scope?



SteveEisner
3 Nov 2006, 2:28 PM
I'm sure this is easy but I'm not able to find an answer -
what's the proper way to scope a function parameter such that the current scope stays?

for instance:
getEl('x').toggle(true, 0.3, this.relayout);

such that the scope when executing this.relayout is still /this/?

Thanks,
Steve

jack.slocum
3 Nov 2006, 2:38 PM
getEl('x').toggle(true, 0.3, this.relayout.createDelegate(this));

createDelegate is on every function (it's in yutil.js) and can override parameters as well. If you are calling this method a lot, it makes sense to store a delegated function and pass the same one.

SteveEisner
3 Nov 2006, 3:00 PM
thanks! that works great