I am working on an application using RequireJS AMD loading method.
I have my modules dynamical picked up from a configuration file into an array
var amd_modules = ["module1", "module2","module3"]
now I have my requireJS code
require(amd_modules, function(result) {
console.log("All modules loaded");
}
Now, the result variable shows the first module which is “module1”. How can I get other modules also into variable inside the function() parenthesis.
For eg,
require(amd_modules, function(module1, module2, module3) { //
}
I can’t write the above hardcoding because the number of dynamic variables are not known until run time. Do let me know how I can catch the objects dynamically inside the function.
Thx
Simply use
arguments:However, unless you have a good reason to do so, you probably want to rethink the way you are designing your application – even at the topmost level your modules should be simple and testable. Having a widely varying number of dependencies indicates that you are probably trying to do to much in your callback function. Break each code path out into its own module and then switch only on your top-level dependency instead. In code: