I have created module
myModule.js
require(['jquery'],function($){
return {
init: function(){
$('.test').hide();
}
}
});
config:
require.config({
baseUrl : "js/",
paths : {
jquery : 'lib/jquery/jquery-2.1.1',
myModule : 'lib/modules/myModule
},
shim : {
}
});
Now I want to use mymodule.init function in other module in proper place (lets say after AJAX load)
require(['jquery', 'myModule'],function($, myModule){
...
myModule.init();
...
});
Here I have an error:
Cannot read property 'init' of undefined
What I did wrong?
In
myModule.js
you callrequire
. You should calldefine
instead so that your module is defined. Adefine
call with a first argument that is a dependency list and a second argument that is a function is somewhat like arequire
call with the same arguments but additionally defines your module.