Brendan gets a special request from the audience about which is more optimized and why, the Closure pattern espoused by Douglas Crockford, OR the standard JavaScript Prototypal inheritance pattern. A longer (or normal depending on perspective) and more nerdy dive than previous episodes, so prepare to have your mind blown away. Brendan discusses how the compiler can (and does) automatic optimization and caching on the prototypal pattern that is otherwise hard or complex, but more importantly not done, for the closure pattern. 10 minutes in all, but well worth your time - we promise.
- JSFiddle
- Doug Crockford
- JavaScript: The Good Parts
- Closure Object Pattern
- Prototypal Inheritance Object Pattern
- Prototypal Inheritance with Explicit Function Hoisting
- JavaScript Prototype Chain
- Inheritance Revisited (MDN)
- Polymorphic Inline Caching
- JavaScript Closure Pattern
- "That Hurts! ... Millions of Millions of Methods"
- R. Kent Dybvig
- "Closure pattern does not win over the prototypal pattern in efficiency"
- You shouldn't prematurely optimize!
- Note: When writing nested functions, (...) evaluation creates a fresh object which potentially leads to a high cost.
- Measure before optimizing, use statistics not "feelings".