I came across the below posts about custom event handling in JavaScript. From these articles, there are two ways (at least) of handling/firing custom events:
- Using DOM methods (createEvent, dispatchEvent)
- How do I create a custom event class in Javascript?
- http://the.unwashedmeme.com/blog/2004/10/04/custom-javascript-events/
- Custom code
- http://www.nczonline.net/blog/2010/03/09/custom-events-in-javascript/
- http://www.geekdaily.net/2008/04/02/javascript-defining-and-using-custom-events/
But what is the recommended way of handling (firing & subscribing) custom events?
[Edit] The context for this question is not using any libraries like jQuery, YUI,... but just plain JavaScript
[Edit 2] There seems to be a subtle differences, at least with the error handling. Dean Edwards ( http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/ ) is recommending the former way for custom event handling. Can we say this a difference?