diff --git a/src/core/main.js b/src/core/main.js index 75d10c7398..93d634198c 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -36,6 +36,7 @@ class p5 { // global mode. static instance = null; static lifecycleHooks = { + init: [], presetup: [], postsetup: [], predraw: [], @@ -138,6 +139,8 @@ class p5 { bindGlobal(p); } + this._runLifecycleHookSync('init'); + const protectedProperties = ['constructor', 'length']; // Attach its properties to the window for (const p in this) { @@ -422,11 +425,17 @@ class p5 { } async _runLifecycleHook(hookName) { - for(const hook of p5.lifecycleHooks[hookName]){ + for (const hook of p5.lifecycleHooks[hookName]) { await hook.call(this); } } + _runLifecycleHookSync(hookName) { + for (const hook of p5.lifecycleHooks[hookName]) { + hook.call(this); + } + } + _initializeInstanceVariables() { this._accessibleOutputs = { text: false,