Global mode versus instance mode for namespace isolation in multi-sketch pages
0 reputation · 12 Feb 2026, 20:57 UTC
Multi-sketch page with shared global namespace
The goal is to run multiple p5 sketches on the same page without accidental collisions between p5 functions, sketch variables, and third-party scripts.
Global mode attaches p5 functions such as createCanvas and draw to the window object, offering terse syntax from early examples. Instance mode encapsulates the sketch inside a callback passed to new p5(), keeping p5 properties on the instance.
Both modes expose the same rendering APIs and lifecycle functions, but differ in namespace access. There is an ongoing repository discussion about deprecating global mode to encourage module practices, with no firm removal date set.
Does instance mode provide complete isolation of p5 properties from window in current stable releases? What migration expectations exist for sketches that rely on window-bound p5 functions if global mode is deprecated? Which mode preserves compatibility with libraries that assume global p5 symbols?