News

Don't forget addEvent!

Thursday, May 25th, 2006

After reading Dustin's post about forgetting addEvent, I have to disagree.
Not with the part about using Yahoo's new Event Utility (that part I DO agree with), the part I disagree with is dropping of the addEvent function.

You see, most folks already have some form of addEvent, with all of the standard params, so why force them to go through their code, and replace addEvent with "YAHOO.util.Event.addListener"?

The easier solution is to take your current addEvent function, and make it a wrapper for the new Yahoo event utility, like so:


function addEvent(el, sType, fn, oScope, bOverride){
YAHOO.util.Event.addListener
(el, sType, fn, oScope, bOverride);
}

Now you have an easy way of integrating it into your current scripts without having to rewrite all of your code.

Perhaps a bit obvious to some, but perhaps helpful to others :)

» Nate Cavanaugh @ 9:40 am

2 comments · Leave one

These 2 people have opinions

Tom said:

What?

Dustin Diaz said:

Indeed, don't forget it. But just so you know, there's a nice little (nifty) shortcut (only by a couple of characters). You can user YAHOO.util.Event.on() which does the same stuff as addListener. Other than that, namespacing in general is a good idea. It avoids conflicts when you end up having to share you code... or rather, if someone wants to use the code from your site, you can be sure that it won't be conflicting with someone elses. If none of that makes sense, just be happy that Yahoo has done us all the favor of putting everything under the YAHOO namespace :).

Share some insight

*
*
*
*
*


Listening to

  • Glen Hansard

    Trying to Pull Myself Away
  • Glen Hansard

    Fallen from the Sky
  • Benzos

    On Your Own
  • Glen Hansard

    Lies
  • Glen Hansard

    Lies