Reputation: 2887
When I load a module using requirejs, do I use the file name or the variable name defined in the module.
For example in the module definition mymodule.js
define( function () {
var module = 'Hello World!';
return module;
});
And then in the consuming module foo.js
Do I call it with:
require( [mymodule], function (module) {
console.log(module);
});
Or
require( [mymodule], function (mymodule) {
console.log(mymodule);
});
Upvotes: 0
Views: 784
Reputation: 8044
Technically you can call it whatever you like, but one limitation of just using module
is what do you do when you have two modules? module2
? It's better (and more common) to name the parameter to match the module name:
require(['ajaxloader', 'modules/carousel', 'jquery'], function(ajaxloader, carousel, $){
});
In the above example you can see that even if the module has a path it makes sense to just use the module name. And there are always exceptions, in this case using $
instead of jquery
.
Upvotes: 2