I have since learned better. Here’s how.
The Videos (or: Seven Episodes of Awesome)
I strongly recommend watching the Crockford videos (I could make a CRockford Files joke here, but I fear my father would be the only one to get it) carefully with a text editor and web browser open, and your finger on the rewind button. Crockford doesn’t waste words and packs every minute with relevant information.
Concepts (or: Pay Attention!)
Another huge concept I had to wrap my head around was Javasript’s prototypal inheritance; it makes the language unlike any other popular programming language.
As you’re watching the videos (in fact, why are you still reading this?), keep an eye out for some concepts:
- Closure–what it means, how it works.
- The differing meaning of
thisin different contexts. This concept is called “binding”, and it can be a huge source of confusion.
- Functions are objects. Function names exist in the same scope as variables. Functions can have their own data members. All of these concepts are departures from what you might know from Ruby or PHP.
- Prototypal Inheritance.
- Global variables are everywhere, and there is no way to prevent your global variables from conflicting with any script you use on your site, or pull from some other site. If you’re not declaring your variables inside a function with the
varkeyword, they are global.
Once you’ve got a reasonable grasp of the concepts you can start to see how frameworks fit in. The Advanced series in particular gives a lot of context to help explain how the Prototype framework is different in philosophy from jQuery (although it doesn’t mention either framework directly).
What Next? (or: Links To Things)
If you’re still scratching your head about the concept of binding, this A List Apart article helps to clarify. Be warned that it does not talk about constructor-style binding (the kind that happens when you use the
new keyword), which is an important thing to know about. Crockford recommends rarely or never using
new, but he explains how it works in one of the advanced videos.