I’m working on a project which is javascript intensive. It’s probably 90% of this app. So I was looking for a way to sharpen my javascript.
So I heard that I should pick up “JavaScript: The Good Parts” to help learn how to structure javascript for use in the dom and elsewhere.
Now that I’ve gotten it and read through it, I wish I’d had it years ago. Crockford skillfully guides you through javascript, showing you the grammar and how it works. All the while carefully explaining the pitfalls and how to avoid them.
He shows you how, even though it looks like a C based language, it shares more with lisp. As well as how to create objects that look and act more to how you would create them in a C based language.
One thing that I’ve known for sometime is the scoping problems with javascript. There is no block scope. There is function scope. So and if(){ doesn’t begin a new scope, variables created there are scoped to the parent function. This is explained very well, and how its just good style to put your variables at the beginning of your function because of that.
The next major pitfall is that the new keyword has some tricky implications if not handled properly, so object names that begin with a capital letter such as Object are meant to be run with the new keyword even though they are able to be executed as var x = Object(); this is just bad news.
I’m now a firm believer that javascript is an amazing dynamic language, with a few blemishes and a bad reputation. This book is all of 130 pages and is deceptively small, given how pumped I am to write code. Also the railroad diagrams describing the grammar opened my eyes to how I can think of other programming languages and statements in general.