Functions & patterns
16 steps in 5 sets of JavaScript.
The parts of JavaScript that reward understanding rather than memorizing. Closures first, then function composition, generators, and finally prototypes and the machinery underneath class.
Sixteen steps. None of it is required to ship something. All of it is required to read what other people shipped.
Closures
- Closures as stateA function that outlives its scope keeps the variables it used.
- Run a function onceWraps a function so it runs the first time and returns that result forever after.
- MemoizeCaches a function's results by argument so the second call is free.
- LRU cache with MapA fixed-size cache that evicts the least recently used entry, built on Map's insertion order.
Composing functions
- CompositionSmall functions, combined left to right or right to left.
- Currying and partial applicationFixing some arguments now and the rest later.
- Function compositionComposes functions left to right so data flows through them in reading order.
- DebounceWaits for the calls to stop before doing anything, which is what a search box wants.
- ThrottleLets one call through per interval and drops the rest, which is what a scroll handler wants.
Generators
- GeneratorsFunctions that yield a stream of values lazily.
- Generators, furtherTwo-way communication: yield sends out, next sends in.
Objects under the hood
- Proxy and ReflectIntercepting property access, which is how observables are built.
- SymbolsUnique keys that never collide, and the well-known ones with meaning.
- Getters and settersComputed properties that look like plain fields.
- Keeping data immutableCopy, do not mutate — and know how deep the copy goes.
Encore
- tail-log.jsSummarize an access log from a file or stdin.