> They can be bubbled, cancelled etc.

No they can't be bubbled, there is only one DOM node, they could be
cancelled but that has little point because again there is only one DOM
node. You could stop immediate propagation but that's just really annoying
in this pattern

Note that using DOM events has a seriously large run-time overhead.

Also note that dean edwards has covered this topic in detail :
http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/

Your also dispatching the same event multiple times. Which won't work on
some browsers. Your also relying on DOM2 events and have no fallback for IE

this._evt = document.createEvent('Event');
this._evt.initEvent('change',true,true);

Note that you can create a CustomEvent instead and initialize that custom
event with a details object.

Model.prototype.set = function(key,val){
this._fields[key] = val;

        var evt = document.createEvent("CustomEvent");
        evt.initCustomEvent("modelChange", true, true, { key: key, val: val
});
this.domnode.dispatchEvent(evt);
};

You can then listen on "modelChange" and get the data through event.detail.
I covered more about custom events in a recent article :
http://raynos.org/blog/11/Native-Custom-events-made-easy


On Fri, Jan 13, 2012 at 6:24 AM, Rajat Mittal <lifeinafol...@gmail.com>wrote:

> I have recently covered up how to do custom events in javascript in a blog
> post.
>
> I know its a well covered topic but I think I have a interesting approach
> to it.
>
> I would love to have a review and improve the post at
> http://javascriptturnsmeon.posterous.com/custom-events-in-mvc-javascript
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to