11. What about var? var PREVENTS global scope inside functions Scoping
12.
13.
14. Lexical Scope Language parsing happens in phases: Phase 1: Lexing (tokenizing) Phase 2: Parsing Phase 3: Other stuff, like compiling to machine code, etc.
15. Lexical Scope Variables declared in the current lexical environment are in lexical scope E.g. function parameters are usually only available inside a function (function scope) Also known as static scope, because it only requires static analysis E.g. the runtime value of the variable is irrelevant
16. Dynamic Scope Remember when we didn’t use varthat one time? That’s called dynamic scope. Global stack of variables Any time a variable is referenced, it pushes (or pops) the global stack, always using the most recent value of the variable
37. Currying Currying is when you have a function that takes two parameters, and you turn it into a function that takes one parameter, lexically binding one of them, and return that lexically bound function (closure).
38. Currying (and uncurrying) Currying is when you have a function that takes two parameters, and you turn it into a function that takes one parameter, lexically binding one of them, and return that lexically bound function (closure). Uncurrying is exactly the opposite
40. The Module Pattern Coined by Douglas Crockford of JSON/Yahoo! fame A JavaScript design pattern for creating private variables Awesome
41. The Module Pattern Makes heavy use of the fact that functions are the only way to create lexical scope Creates public APIs that use internal, private variables
46. Inheritance Inheritance is tricky in JavaScript There are two types: Classical (like Java) Prototypal (not like Java)
47. Classical Inheritance Classical inheritance is hard in JavaScript There is no extends There is no implements The constructor is hidden The constructor doesn’t do what you think it will The new keyword doesn’t do what you think it will The this keyword is not always in the scope you think it is
49. Classical Inheritance If you don’t use prototype, then evict is not defined on our Cat instance Think of it as a static method, and you can’t execute a static method non-statically