To this point, we have been using things like redirectUrl and cookieNotices out of thin air, but how exactly do these components become available to our code? The answer is, via RequireJS, a library that underlies nearly every other JS feature built into Magento. The overall role of RequireJS is simple; it is a JS module system that implements the Asynchronous Module Definition (AMD) standard, which serves as an improvement over the web's current globals and script tags.
We have already seen the format of these AMD modules in the preceding examples, which comes down the following:
define(['dep1', 'dep2'], function (dep1, dep2) {
return function () {
// Module value to return
};
});
The gist of AMD modules functionality comes down to each module being able to:
- Register the factory function via define
- Inject dependencies, instead of...