@@ -48,7 +48,7 @@ var p5 = function(sketch, node, sync) {
4848
4949 /**
5050 * Called directly before <a href="#/p5/setup">setup()</a>, the <a href="#/p5/preload">preload()</a> function is used to handle
51- * asynchronous loading of external files in a blocking way. If a preload
51+ * asynchronous loading of external files in a blocking way. If a preload
5252 * function is defined, <a href="#/p5/setup">setup()</a> will wait until any load calls within have
5353 * finished. Nothing besides load calls (<a href="#/p5/loadImage">loadImage</a>, <a href="#/p5/loadJSON">loadJSON</a>, <a href="#/p5/loadFont">loadFont</a>,
5454 * <a href="#/p5/loadStrings">loadStrings</a>, etc.) should be inside the preload function. If asynchronous
@@ -238,7 +238,8 @@ var p5 = function(sketch, node, sync) {
238238 }
239239 }
240240
241- var userPreload = this . preload || window . preload ; // look for "preload"
241+ var context = this . _isGlobal ? window : this ;
242+ var userPreload = context . preload ;
242243 if ( userPreload ) {
243244 // Setup loading screen
244245 // Set loading screen into dom if not present
@@ -252,11 +253,11 @@ var p5 = function(sketch, node, sync) {
252253 var node = this . _userNode || document . body ;
253254 node . appendChild ( loadingScreen ) ;
254255 }
255- // var methods = this._preloadMethods;
256- for ( var method in this . _preloadMethods ) {
256+ var methods = this . _preloadMethods ;
257+ for ( var method in methods ) {
257258 // default to p5 if no object defined
258- this . _preloadMethods [ method ] = this . _preloadMethods [ method ] || p5 ;
259- var obj = this . _preloadMethods [ method ] ;
259+ methods [ method ] = methods [ method ] || p5 ;
260+ var obj = methods [ method ] ;
260261 //it's p5, check if it's global or instance
261262 if ( obj === p5 . prototype || obj === p5 ) {
262263 if ( this . _isGlobal ) {
0 commit comments