Introducing Asynchronous Module Definition

Asynchronous Module Definition (AMD) format for creating modules in JavaScript, is targeted for use in browsers. This format proposes a particular way for defining modules so that modules and their dependencies can be loaded into the browser asynchronously.

There are two key methods that you need to use when creating and consuming AMD modules, these are define and require methods.

The idea is that we create a module using the global define method and then we can import that module in other parts of the code (other modules) using the global require method.

Defining modules using AMD format

Here is how a module can be defined in AMD format:

define('moduleOneId', ['dependency'], function(dependency) { return ...

Get Modular Programming with JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.