简体   繁体   中英

How do you syncronize javascript modules at different ajax levels?

Module pattern:

APP.MODULE.MYMODULE = (function(OTHERMODULE) {

   //ajax call with new module initialization

}(APP.MODULE.OTHERMODULE));

Let's assume that there is a lot of ajax module initializations of different levels. How do you syncronize javascript modules at different ajax levels ?

The actualt problem is:

 APP.MODULE.OTHERMODULE // is underfined if OTHERMODULE is initialize on ajax request 
 // and we can't pass undefined object as a dependency

It feels like passing into a another module APP.MODULE 'namespace' with not initialize OTHERMODULE is a bad practice. Also javascript file reordering takes a lot of time as well as circle dependencies.

Do you init new modules on success or done ajax result? How do you organize the code in files?

you might want to look at requirejs. then you can say things like

define ("MYMODULE", ["OTHERMODULE"], (other){
/* your code depeinding on othermodule here */
});

this way you can keep your modules pure and manage dependencies

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