typestar

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.

Start this tour

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

Objects under the hood

Encore

  • tail-log.jsSummarize an access log from a file or stdin.

The other JavaScript tours