TruerWords Logo
Google
 
Web www.truerwords.net

Search TruerWords

Welcome
Sign Up  Log On

“Re: Creating Custom Events with JavaScript: Decoupling”

From: Mike Czepiel In Response To: 5568  Creating Custom Events with JavaScript: Decoupling
Date Posted: Thursday, March 8, 2007 3:17:10 PM Replies: 0
   
Enclosures: None.
Not sure what your preferred method of gathering feedback is, but I have a patch I'm using on event_mixins.js I figured you may find useful.

The diff is as follows:

198c198,205
<               var cb = this[ onEvent_name ].bindAsEventListener( this );
---
>               //added this in to allow for anonymous function handling of an event
>               var eventHandler = this[onEvent_name];
> 
>               if(typeof(onEvent_name) == 'function') {
>                       eventHandler = onEvent_name;
>               }
> 
>               var cb = eventHandler.bindAsEventListener( this );

Basically I didn't like having to create function following any particular naming scheme, it felt a little coincidental. Additionally I'll often handle the event in an anonymous function which will call the correct instance method. Ideally the instance methods don't even know they're being called due to an event having occurred.

I'm using the code on a pretty high profile site at the moment without any glaring issues with this patch, but I'm sure there's room for improvement.

Thanks for the the great work you've done.


Discussion Thread:

There are no replies.

Trackbacks:

There are no trackbacks.


Until August 31
My Amazon sales
benefit the PMC

Homepage Links

Apr 1 - Aug 31
Ad revenue
benefits the PMC


TruerWords
is Seth Dillingham's
personal web site.
Read'em and weep, baby.