Stupid pet tricks: functions as state

It seems the real culprit for containing state isn’t mentioned: closure.

Returning state via a function closure, for example, is at the core of implementing trampolines in JavaScript in order to implement stackless recursion.

And then there is this (2003):

  • Objects are merely a poor man’s closures
  • Closures are a poor man’s object
6 Likes