简体   繁体   中英

(Brackets IDE) html5 reference javascript files

I have been following a tutorial on videogame making with the Brackets IDE (using HTML5 and JavasScript). I was asked to divide the code in different files and reference them in the main one, but it is not working, it does not recognize the variables declared in the other files.

The code is the following:

Current code

You should use a sort of namespacing for your code. So still if it is split in different files it will refer to a master source.

// script 1
(function(global){
    var framework = global.framework = global.framework || {};

   framework.UtilityOne = function(){};
   framework.collectionOne = f[];

})(this);


 // script 2
(function(global){
    var framework = global.framework = global.framework || {};

   framework.UtilityTwo = function(){};
   // check framework reddiness
   // because you don't know when all files are loaded 
   //and i which order they loaded
   framework.ready(function(){
      framework.collectionOne.push('something');
   });

})(this);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM