Your habit is a very very good one, and something I''ve been preaching
for a
long time. Once you are dealing in terms of self contained widgets within a
rich internet application, this becomes paramount.
However, as for the question about onXXX vs. the W3C model (which
Event.observe abstracts for us)... obviously the W3C is preferred is almost
all cases as it is more robust and allows for multiple handlers on a single
element/event pair, as well as dynamic attachment/detachment. Having said, I
have run into cases where the onXXX demonstrates more desirable behavior
that becomes a major pain in the arse to emulate with the W3C model, but my
woes were mostly around capturing keycodes in a case-sensitive context from
keypresses. The W3C model will always return the lower case version of a
character code, and I guess they expect you to also check for the shift key
being depressed to detect case, but it doesn''t take into account the
possibilty of CAPSLOCK. Anyway, for those places I ended up using onXXX to
attach the keypress handlers, as it returns the proper character code in all
cases...
So anyway. The long and short of it, use the W3C model until it doesn''t
work, then use whatever you have to get your problem solved.
On 10/20/06, Colin Mollenhour
<eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org>
wrote:>
>
> What are the pros and cons of using Event.observe vs. element.onxxx >
somefunction ?
>
> I noticed that a lot of sau code doesn''t use Event.observe. For
example,
> InPlaceEditor uses
> this.form.onsubmit = this.onSubmit.bind(this);
>
> In my code I''ve made a habit of using the equivalent (for
example):
> this.onSubmitListener = this.onSubmit.bind(this);
>
Event.observe(this.form,''submit'',this.onSubmitListener);
> So that in my "dispose" methods I can cleanup properly by
calling:
>
Event.stopObserving(this.form,''submit'',this.onSubmitListener);
>
> Am I just wasting my time? Is the Prototype method more or less
> leak-prone than the .onxxx = function method?
>
> Thanks,
> Colin
>
>
> >
>
--
Ryan Gahl
Application Development Consultant
Athena Group, Inc.
Inquire: 1-920-955-1457
Blog: http://www.someElement.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---