JavaScript Idioms Every Webdev Should Grok
JavaScript (the language, not the browser bindings for the DOM, etc.) can be either brutally hard or refreshingly flexible. It's difficulty is directly related to how well you grok a couple of core concepts. I'm going to just list them and leave in-depth explanations to Tom's forthcoming book on advanced JavaScript.
Here goes:
- Everything in JavaScript is an Object. Even functions
- Every object is always mutable
- The dot operator is equivalent to de-referencing by hash (e.g.,
foo.bar === foo["bar"]
) - The
new
keyword creates an object that class constructors run inside of, thereby imprinting them - Functions are always closures (combine w/ previous rule to create OOP)
- The
this
keyword is relative to the execution context, not the declaration context - The
prototype
property is mutable
If all of that makes sense to you, JavaScript can be a fun, liberating experience. If not, it's going to be a world of pain and broken expectations as you shed the baggage of less dynamic languages.
Good luck.