javascript - How to combine different ways of module loading in RequireJS? -
is a code (module module 1, module 2, and module 3 load at the same time):
Define (['module1', 'module2', 'module3'], function (module1, module2, module3) {return} {/ * ... * /};} );
There is another (one module after module 1 and module 2 is loaded one and module 3 is loaded on demand, dynamically):
How to add these two methods and modules 1 and 2 can be loaded as the first example at the same time, and module 3 as a second example dynamically Additional modules to load)?
The second example does not work as you imagine. defined (function (requires) {...})
Syntax is the only one which basically converts to asynchronous call as the first example, to load all the three required modules in parallel Before the module function is executed.
If you intend to actually implement the order of loading, you will find something like this:
defined (function (required) {// these two Modules will load parallel Var modules 1 = Required ("module 1"); var module 2 = expected ("module 2"); return {loadModule3: function () {// loaded this module "on-demand" When `loadModule3` is required ([" module 3 "], function (module 3) {// here modules 1,2 and 3 will be available S});}};});
Please note, that you call "on-demand" loading, will ensure that "module 3" is available inside the callback function, the code path available on module 3 Must be available.
Comments
Post a Comment