@@ -37,7 +37,7 @@ class p5 {
37
37
//////////////////////////////////////////////
38
38
// PUBLIC p5 PROPERTIES AND METHODS
39
39
//////////////////////////////////////////////
40
-
40
+ this . _isGlobal = ! sketch ;
41
41
/**
42
42
* A function that's called once to load assets before the sketch runs.
43
43
*
@@ -286,7 +286,6 @@ class p5 {
286
286
this . _glAttributes = null ;
287
287
this . _requestAnimId = 0 ;
288
288
this . _preloadCount = 0 ;
289
- this . _isGlobal = false ;
290
289
this . _loop = true ;
291
290
this . _startListener = null ;
292
291
this . _initializeInstanceVariables ( ) ;
@@ -661,21 +660,11 @@ class p5 {
661
660
// ensure correct reporting of window dimensions
662
661
this . _updateWindowSize ( ) ;
663
662
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
-
673
663
const friendlyBindGlobal = this . _createFriendlyGlobalFunctionBinder ( ) ;
674
664
675
665
// If the user has created a global setup or draw function,
676
666
// assume "global" mode and make everything global (i.e. on the window)
677
- if ( ! sketch ) {
678
- this . _isGlobal = true ;
667
+ if ( this . _isGlobal ) {
679
668
p5 . instance = this ;
680
669
// Loop through methods on the prototype and attach them to the window
681
670
for ( const p in p5 . prototype ) {
@@ -710,8 +699,14 @@ class p5 {
710
699
p5 . _checkForUserDefinedFunctions ( this ) ;
711
700
}
712
701
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 ( ) ;
714
708
709
+ // Bind events to window (not using container div bc key events don't work)
715
710
for ( const e in this . _events ) {
716
711
const f = this [ `_on${ e } ` ] ;
717
712
if ( f ) {
0 commit comments