Douglas Crockford’s Google Talk – JavaScript: The Good Parts
January 8, 2011 § Leave a comment
My notes from Douglas Crockford’s Google Talk based on his book, JavaScript: The Good Parts.
- JavaScript is misunderstood
- DOM is source of poor performance, not JS
- If you’re going to use a language, learn it… JS is easy to use without learning it and that’s a cause for misunderstanding it
- JS is loosely typed
- Amount of testing required in Java and JS is about the same… the type checking happens through the tests
- You don’t have to worry about type checking
- bad parts: global variables; + adds and concatenates; semicolon insertion; typeof; with and eval; phony arrays; == and !=; false, null, undefined, NaN
- arrays are hashtables with indexes as keys
- always use ===, never use ==
- if you ask for a property that doesn’t exist, you get undefined
- bad heritage: blockless statements; expression statements; floating point arithmetic; ++ and –; switch
- DC doesn’t use ++ and —
- good parts: lambda, dynamic objects, loose typing, object literals
- two schools of inheritance: classical (most OO languages), prototypal (JS)
- prototypal inheritance: class free; objects inherit from objects; an object contains a link to object to inherit from
- “new” operator is required when calling a Constructor function… dangerous and DC doesn’t use it anymore
- function variable scope, but no block variable scope
- create objects using closures
- start block statements on the same line as the declaration… semicolon insertion will rear its ugly head
- “Working with the Grain”
- JSON derived from the good parts of JS
- JS is really based on Scheme
- JSLint identifies the bad parts — do everything it says, it’s smarter about JS than you are
- If you avoid the bad parts, JS works really well — it is possible to write good programs in JS