Thanks for the feedback, the bind(this) worked like a charm, I was
beating my head against my monitor trying to come up with a solution.

I'm confused, though, as to why javascript loses the reference to
"this" without that bind method can somebody explain? Also why doesn't
 onSuccess: this.switchPrompt.bind(this) fire automatically, because
it has "()" at the end. I know I tried this.switchPrompt(evt) at one
point, and instead of pointing the switchPrompt method to be fired
onSuccess, it just always fired it automatically - because it had the
parenthases at the end.

Thanks for the other thoughts as well, I implemented both of them,
just to be on the safe side.

On 10/27/05, Rahul Bhargava <[EMAIL PROTECTED]> wrote:
> A few thoughts :
>
> 1) You need to bind the object to get it to work:
>   onSuccess: this.switchPrompt.bind(this),
>   onFailure: this.dontCheck.bind(this)
> that will fake out Javascript and set up the "this" reference to work
> correctly for you I think.
>
> 2) On another note, I've noticed that it's appropriate to use the
> Event.observe() method to set up onclick listeners.  For instance:
>
> Event.observe(this.chkbox,
> 'click',this.switchRequired.bindAsEventListener(this));
>
> In this case it probably makes no difference, but in general it helps
> you around browser inconsistencies with events and listeners.
>
> 3) Do you really want to cache the whole event? I don't know if that
> will cause any weirdness because of the browser trying to destroy it or
> something.  In general I would cache the source of the event only, which
> is probably what you need anyway:
>   this.cache = Event.element(evt);
> but maybe I'm wrong and you do want the whole event and caching it is
> not a problem.
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to