|
|
“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. | ||
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.
There are no trackbacks.
|
TruerWords
is Seth Dillingham's personal web site. Read'em and weep, baby. |