Inconsistent behavior across browsers
This is really important to keep in mind, javascript is 'nearly' equal in ALL browser and differences are usually in the obscure areas. Where most browser inconsistency is perceived however is not in JavaScript but in the DOM API. JavaScript has a bad rep mainly due to poor/incomplete or even outright different DOM implementations.
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 (window
) and 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 usually a safeguard, but in JavaScript, 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).
Advice
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 ;)
I would also advice reading about design patterns which are useful in any language, including JavaScript. This will simply make you a better programmer period.
How I mastered javascript
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)
Writing code and more importantly REwriting code whilst always questioning myself was in my case the best learning school. Fortunatly I began in a period where jQuery didn't even exist and making your own toolkits was a must. Frameworks and toolkits are helpful, but only teach you how to use their API's, they don't teach you much about JavaScript in depth.