js-dojo

4 patching foreign code

What this module drills

Adding behaviour to code you do not own and cannot edit — a third-party engine class, a settings object from a library, a hook API with a typo in it. The tools are all prototype tools: a stateless dispatcher on the prototype, per-instance state born in an init hook, Symbol and WeakMap stashes, non-enumerable helpers.

Why it bites

The natural first attempt — state in a module-level variable — works with one instance and breaks with two. A lobby running a dozen matches flushes match A's queue into match B. Koan 01 ships that bug and has you fix it the way engine plugins actually do.

Order

01 is the pattern everything else uses. 02 (a disciplined wrapMethod) and 03 (where to hang your own metadata on someone else's objects) are the core. 04 and 05 are defensive: keep helpers out of enumeration, and guard against an API name that is not what the docs say.