PDA

View Full Version : Function parameter keeping scope?


SteveEisner
11-03-2006, 05: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
11-03-2006, 05: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
11-03-2006, 06:00 PM
thanks! that works great