RequireJS is an AMD implementation. AMD (Asynchronous Module Definition) is a standard on how to write modules in JavaScript.
There are other specifications such as CommonsJS that is used by Node.js
, and they all work. But AMD is different from the others, in that it works in browsers seamlessly between development and production.
It was created based on the specifics of the browser environment, where things cannot always be synchronous, and loading a different module might require a request that will be completed at a later time.
Before we can go any further and start the project setup on RequireJS, we first need to understand the structure of an AMD module.
In Chapter 3, Testing Frontend Code, we have seen how to use the module pattern with IIFE to organize our code. An AMD module is built on the same principles: a file and a function. However, instead of using an IIFE, we invoke the AMD define
function passing a callback function as an argument. At a later time...