SteveEisner
12 Nov 2006, 11:18 PM
I keep wanting to have an event handler that accepts a parameter /and/ maintains the scope of its definition... In other words,
getEl('homeButton').on('click', this.mode, (2), this, true);
...
mode: function(ev, arg) { this.displayMode = arg; }
Not sure if that fake code makes it clear, but what I want is for "this" in this.mode to be the same as it was in the init routine which attached the onClick event.
The problem is that it seems I can either specify an additional parameter, OR a parameter that's also the functional scope, but not a parameter plus separate functional scope. I'm kind of curious why the arguments are "param-object, bool" when perhaps "param-object, scope-object" would have been more general purpose? [I haven't looked into the full implementation so perhaps there's a technical reason that the two can't be kept independent...]
I've gotten around this by passing a composite object with "this" and the parameter packaged up together, but am I missing some easier way of doing this?
getEl('homeButton').on('click', this.mode, (2), this, true);
...
mode: function(ev, arg) { this.displayMode = arg; }
Not sure if that fake code makes it clear, but what I want is for "this" in this.mode to be the same as it was in the init routine which attached the onClick event.
The problem is that it seems I can either specify an additional parameter, OR a parameter that's also the functional scope, but not a parameter plus separate functional scope. I'm kind of curious why the arguments are "param-object, bool" when perhaps "param-object, scope-object" would have been more general purpose? [I haven't looked into the full implementation so perhaps there's a technical reason that the two can't be kept independent...]
I've gotten around this by passing a composite object with "this" and the parameter packaged up together, but am I missing some easier way of doing this?