Google Groups Home
Help | Sign in
Message from discussion Any need for addEventListener() and attachEvent() at all?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
David Golightly  
View profile
 More options Nov 24 2006, 2:30 am
Newsgroups: comp.lang.javascript
From: "David Golightly" <davig...@gmail.com>
Date: 23 Nov 2006 23:30:59 -0800
Local: Fri, Nov 24 2006 2:30 am
Subject: Re: Any need for addEventListener() and attachEvent() at all?

Peter Michaux wrote:
> David Golightly wrote:
> > Peter Michaux wrote:
> > > I would really like to write a robust event library that
> > > just works and doesn't suprise me some day down the road.

> > Yeah, I guess that's why I included the DOM 0 fallback.  (Which could
> > be robustified by implementing the Yahoo algorithm.)  The idea is you
> > have a good enough library that wraps all the browser inconsistencies
> > of all time; you develop this library with unit tests, and test &
> > refine on all browsers, then you just use that library for all your
> > apps and stop worrying about browser inconsistencies for every app you
> > develop.  I share your vision!

> Here is my rough draft of the library. If anyone is interested please
> take a look and let me know what you think.

> http://peter.michaux.ca/temp/event.html

> I need to add many more unit tests and docs but I think that's enough
> for today.

> > > What I'm wondering is if the DOM0 implementations in the browsers have
> > > any bugs like the DOM2/Safari bugs.

> > I wonder if you couldn't just implement the functionality of the DOM
> > Level 2 events module in JS - it looks like most of it's possible.
> > (Though it most certainly wouldn't be as fast as native support, where
> > available.)

> I don't know if the performance would be noticably different even in a
> dragdrop situation. After any bugs are out of the library above then
> performance tests can be made.

> Peter

Hey Peter,

Your code looks good and runs well, but I'm still a bit concerned about
performance here.  In the example test cases you have, there's not a
problem, but consider your code here:

        el['on' + type] = function(e) {
                             e = e || window.event;
                             var listeners =
arguments.callee.listeners;
                             for (var i=0, len=listeners.length; i<len;
i++) {
                               var l = listeners[i];
                               if (l) {l.wrappedFn(e);}
                             }
                           };

Here is the relevant W3C recommendation
(http://www.w3.org/TR/DOM-Level-2-Events/events.html):

quote
Any exceptions thrown inside an EventListener will not stop propagation
of the event. It will continue processing any additional EventListener
in the described manner.
/quote

I was concerned about your implementation's synchronous implementation;
however, it appears that the standard is not clear on whether multiple
events should be called synchronously or asynchronously.  (I believe
the FF is asynchronous for multiple events, which would improve
performance considerably.  Need test to determine whether this is the
case.)

However, what your implementation is missing is fallback error
handling.  If an error occurs in one handler it will prevent the rest
of the handlers from executing.

That's all.  Good work otherwise.

-David


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google