Reputation: 25
recently I have a problem about including other js files using dojo. e.g. : In my 1.js file, I wrote:
require(["dijit/form/Button"], function(Button){
addButton(someWidget);});
and in my 1a.js file, I wrote the function addButton:
function addButton(target){
var b1=new Button({
style: "border: 1px solid green",
label: "xxxxx"
});
target.addChild(b1);
return b1;
}
for 1a.js there must be an error, because I did not require that module, but i add require, the biggest problem is that returned value, I can not get the return value, because of nested funciton.
how can i wrote a js file, which i wrote all my functions, and in another js file, i just call these functions with dojo require("xxxx", function(x){})
Thanks for help!
Upvotes: 0
Views: 1717
Reputation: 8162
dojo.require
is the legacy (<=1.6) loader for the toolkit. Using dojo.require
in one file, made the code available to all files.
Dojo has moved to using the AMD API for loading modules. In 1a.js, you will also need to add the require
statement.
My answers to the following questions will provide a better understanding of the AMD API and the require
statement:
Upvotes: 1