Inconsistent behavior across browsers
Event driven programming:
Event driven programming is a means to accomplish loose coupling (next to dependency injection), an object fires events to whomever is interrested and other programs can listen and act on the events. More then one listener can for example listen and act on a click event, but the click itself is not dependant on it's listeners.
Behavior of anonymous functions
Anonymous functions are no different from named functions, and are used in cases where you simply do not need to store a reference to a piece of code. They are ideal for self executing code, callbacks and oneshot listeners. They should be avoided inside loops and when using them inside recursive functions a good 'thinking it through' is needed.
The keyword this
Global functions can be considered 'methods' of the global scope (
this is a reference to the scope of a method. Where
this is concerned, one needs to really make the distinction between function and method. In other languages,
this is mandatory when a referencing properties and methods on the current scope of a method (except for methods and properties in the global scope).
Lots of awnser already listed the good books and YUI theater movies, they are all worth reading/watching, but the real school is get your hands dirty, so I'll give you an assignment:
- Write an EventDispatcher/Observer/Publisher (same thing, different names/apis) that can:
- fire any event
- invokes the listener function on the scope of itself
- passes an eventObject to each listener function
- invokes each listener in the order they started listening
- can remove specific listeners per eventType
- can be instantiated so each instance has it's own events and listener stack.
Doing this basically teaches you about your last 3 points and gives you a useful reusable pattern. You can cheat ofcourse and look one up, but try to understand it's workings and how you would use it in your programs at the very least ;)
1.) I wrote my own DOM framework (you learn a LOT from this)
2.) I wrote my own Class implementation (starting to learn about structure)
3.) I wrote my own ScriptDependency loader
4.) I read a lot of discussions and follow a bunchload of blogs/twitters
5.) Bought/read the books, watched the YUI theater vids
6.) I awnser questions on Stackoverflow (sometimes I learn a bit more from this STILL)