Reputation: 12388
I'm new to dojo and can't figure out why this is happening
in dojo.html:
require(["dojo/query", "dojo/NodeList-dom", "dojo/domReady!", "a" ], function(query, a) {
query("#greeting").style("color", "red");
alert(a.sheep);
});
in a.js
define([], function() {
var a = {
"sheep": "blah",
}
return a;
});
Requiring and loading module a is fine, but when I try to alert a.sheep, I get undefined. Note: I've also tried declaring sheep : "blah" as well and try changing sheep to an alert function and running a.sheep; which worked.
Upvotes: 1
Views: 280
Reputation: 7352
the reason you cannot access a.sheep
is that there is dojo/NodeList-dom
module in a
variable. The order of elements in define/require
array is bind to the list of arguments in the subsequent function
. So you should write:
require(["dojo/query", "a", "dojo/NodeList-dom", "dojo/domReady!"], function(query, a) {
})
Also from the practical point of view I happen to format my code like this:
define([
"dojo/_base/declare",
"dojo/query",
"a",
"dojo/NodeList-dom",
"dojo/domReady!"
],
function(
declare
query,
a
){
return declare(null, {
constructor: function() {}
});
});
Every module on his own line, plus logical clustering of modules via empty lines.
Upvotes: 2