[thelist] javascript default event handlers, default events. [TIP]

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Wed Aug 31 10:10:52 CDT 2005


By the way EventHandler is my cross-browser event handling object.

On 8/31/05, VOLKAN ÖZÇELİK <volkan.ozcelik at gmail.com> wrote:
> > We know exactly where to look for it, as opposed to any
> > particular place in our JS source, perhaps even more than once, or as a
> > result of many conditions.
> 
> Here is the way I do it:
> 
> I attach the events on the page on a single place in the script
> 
> Basically I use this structure:
> 
> PageName.js
> -------------------
> /*I place init at the top of my js file usually named <PageName>.js */
> function init(){
>   .. do initialization logic...
> 
>   var eh=new EventHandler();
>   eh.addEventListener(document.getElementById("foo"),"click",foo_click);
>   eh.addEventListener(document.getElementById("bar"),"click",bar_click);
>   eh.addEventListener(document.getElementById("baz"),"click",baz_click);
> }
> /*I place the handling function just after the init*/
> function foo_click(evt){..}
> function bar_click(evt){...}
> function baz_click(evt){...}
> 
> So it is neat, events are attached at a single place. Behavior is
> separated from code. It is easy to maintain (imho) since you know what
> code belongs to where.
> 
> That is, as long as you follow some logic and some conventions, it is
> even easier (imho) to add/ammend/remove event handling logic on the js
> side.
> 
> Cheers,
> Volkan.
>


More information about the thelist mailing list