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 Joseph's answer, you can also write other modules that depend on shirt
(which is where the real power of RequireJS comes in).
// shirt.js
define({
color: "black",
size : "large"
});
// logger.js
define(function (require) {
var shirt = require("./shirt");
return {
logTheShirt: function () {
console.log("color: " + shirt.color + ", size: " + shirt.size);
}
};
});
// main.js
define(function (require) {
var shirt = require("./shirt");
var logger = require("./logger");
alert("Shirt color is: " + shirt.color);
logger.logTheShirt();
});
Then your HTML can just be