Forum: Rails Spinoffs (closed, excessive spam) prototype Element.observe handler function - how to add more arguments in addition to event handler

57564570dcbfeb09e90c3fb913a7daf4?d=identicon&s=25 mocambo (Guest)
on 2008-06-16 05:34
(Received via mailing list)
$(id).observe('click', this.add( 'name' ).bindAsEventListener(this));

As we know, event handler passed as argument to handler function.
Sample above not correct, but how to add 'name' string argument to
handler function?
E73e8035d6e93443a09f31016773454e?d=identicon&s=25 unknown (Guest)
on 2008-06-16 07:06
(Received via mailing list)
mocambo wrote:
> $(id).observe('click', this.add( 'name' ).bindAsEventListener(this));
>
> As we know, event handler passed as argument to handler function.
> Sample above not correct, but how to add 'name' string argument to
> handler function?

If you have 1.6, you can do

$(id).observe('click', this.add.bind(this, 'name'));

This will put 'name' in the first parameter to this.add().
8cf6d14fe2c55b53ad7f0301ad379010?d=identicon&s=25 I. E. Smith-Heisters (Guest)
on 2008-06-16 20:32
(Received via mailing list)
On Jun 15, 10:05 pm, develo...@ckiweb.com wrote:
>
> This will put 'name' in the first parameter to this.add().

http://www.prototypejs.org/api/function

Function.curry may also be helpful.
This topic is locked and can not be replied to.