I am trying to learn how to use require.js. So I made an HTML page with the following tags in the body.
In addition to Domenic's answer maybe you prefer this way of using the define function without using require functions inside the modules.
// shirt.js
define({
color: "black",
size : "large"
});
// logger.js
define(["shirt"], function (shirt) {
return {
logTheShirt: function () {
console.log("color: " + shirt.color + ", size: " + shirt.size);
}
};
});
// main.js
define(["shirt", "logger"],function (shirt, logger) {
alert("Shirt color is: " + shirt.color);
logger.logTheShirt();
});
I prefer this way, but it's only a matter of taste I guess. (I'm assuming that all the scripts are on the same folder.)