I am really a newbie to dojo but as i started developing a new application with dojo version 1.7.2 i also wanted to use the new AMD syntax for functions. Unfortunately i don
Paul Grime gave you a good example, so I'm just sharing some thoughts.
You don't define all the modules in each function, that's a huge waste of space. Although, even if you try to load a module multiple times, Dojo will only load it once anyway.
This is a simplified module from my latest project, with quite meaningless functionality:
//app module in 'my' folder
define(
[
'app/elements',
'dojo/query',
'dojo/on',
'dojo/fx',
'dojo/_base/fx',
'dojo/dom-construct',
'dojo/_base/event'
//and so on.....
],
function(elements, q, on, fx, baseFx, constr, event)
{
return {
init : function()
{
var node = q(elements.loading);
this.removeNode(node);
this.addEvents();
},
removeNode : function(node)
{
node.remove();
},
addEvents : function()
{
$(elements.buttons).on('click', function(e)
{
alert(q(e).attr('id') + ' was clicked!');
});
}
}
}
Then I get the module by using
define(
[
'my/app',
],
function (app)
{
app.init();
}