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