@@ -37,7 +37,7 @@ class p5 {
3737 //////////////////////////////////////////////
3838 // PUBLIC p5 PROPERTIES AND METHODS
3939 //////////////////////////////////////////////
40-
40+ this . _isGlobal = ! sketch ;
4141 /**
4242 * A function that's called once to load assets before the sketch runs.
4343 *
@@ -286,7 +286,6 @@ class p5 {
286286 this . _glAttributes = null ;
287287 this . _requestAnimId = 0 ;
288288 this . _preloadCount = 0 ;
289- this . _isGlobal = false ;
290289 this . _loop = true ;
291290 this . _startListener = null ;
292291 this . _initializeInstanceVariables ( ) ;
@@ -661,21 +660,11 @@ class p5 {
661660 // ensure correct reporting of window dimensions
662661 this . _updateWindowSize ( ) ;
663662
664- // call any registered init functions
665- this . _registeredMethods . init . forEach ( function ( f ) {
666- if ( typeof f !== 'undefined' ) {
667- f . call ( this ) ;
668- }
669- } , this ) ;
670- // Set up promise preloads
671- this . _setupPromisePreloads ( ) ;
672-
673663 const friendlyBindGlobal = this . _createFriendlyGlobalFunctionBinder ( ) ;
674664
675665 // If the user has created a global setup or draw function,
676666 // assume "global" mode and make everything global (i.e. on the window)
677- if ( ! sketch ) {
678- this . _isGlobal = true ;
667+ if ( this . _isGlobal ) {
679668 p5 . instance = this ;
680669 // Loop through methods on the prototype and attach them to the window
681670 for ( const p in p5 . prototype ) {
@@ -710,8 +699,14 @@ class p5 {
710699 p5 . _checkForUserDefinedFunctions ( this ) ;
711700 }
712701
713- // Bind events to window (not using container div bc key events don't work)
702+ this . _updateWindowSize ( ) ;
703+
704+ // call any registered init functions
705+ this . callRegisteredHooksFor ( 'init' ) ;
706+ // Set up promise preloads
707+ this . _setupPromisePreloads ( ) ;
714708
709+ // Bind events to window (not using container div bc key events don't work)
715710 for ( const e in this . _events ) {
716711 const f = this [ `_on${ e } ` ] ;
717712 if ( f ) {
0 commit comments