I'm started learning using require.js
main.jsrequire(['jquery', 'underscore', 'Module1'], function($, _, Module1) {
Module1.init();
$('#output').html('Hello World!');
});
module1.js
define('Module1', [], function(app) {
var init = function() {
alert('Hello World!') ;
}
return {
init: init
};
});
It's working but I'm wondering that I can change to define('MyApp', [] function(app){}); in module1.js?, and modify my main.js to
require(['jquery', 'underscore', 'MyApp'], function($, _, MyApp) {
MyApp.init();
$('#output').html('Hello World!');
});
Please help, so I can understand more about using require.js.
Thanks.
Edited
With help from below answer, I've modified my coding to
module1.jsdefine('MyApp', [], function(app) {
var init = function() {
alert('Hello World!') ;
}
return {
init: init
};
});
main.js
require.config({
baseUrl: 'js',
paths: {
Module1: 'module1'
}
});
require(['jquery', 'underscore', 'Module1'], function($, _, MyApp) {
MyApp.init();
$('#output').html('Hello World!');
});
Unfortunately I still couldn't get it work, so please give me more advices.