[Proto-Scripty] Re: Passing Variables to Functions in addEventListener Within a Class

2010-08-05 Thread T.J. Crowder
Hi, > Isn't this the one case where bindAsEventListener() is actually > needed? No, more here: http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener ...but Matt was mistaken when he said the argument would show up after the event. When you use #bind, the even

[Proto-Scripty] Re: Passing Variables to Functions in addEventListener Within a Class

2010-08-04 Thread Eric
On Jul 23, 10:14 pm, Matt Foster wrote: > You can just add parameters to the bind call and they will show up in > execution. > > $(id).observe('mousedown', this.myFunction.bind(this, otherParam); > > Then I believe it shows up after the event. Isn't this the one case where bindAsEventListener() i

[Proto-Scripty] Re: Passing Variables to Functions in addEventListener Within a Class

2010-07-23 Thread Matt Foster
You can just add parameters to the bind call and they will show up in execution. $(id).observe('mousedown', this.myFunction.bind(this, otherParam); Then I believe it shows up after the event. function myFunction(event, param){... but in your case, simply binding to "this" will allow you to refe

[Proto-Scripty] Re: Passing Variables to Functions in addEventListener Within a Class

2010-07-23 Thread T.J. Crowder
Hi, Since you're creating the event handler inside your `initialize` function, you can take advantage of the fact it's already a closure by assigning `this` to a local variable (`self` is a common name for it) and then using `self` within the closure (the event handler), since it will inherit it.