Javascript - Asynchronous Module Definition (AMD)

About

The Asynchronous Module Definition (AMD) API specifies a mechanism for defining modules such that the module and its dependencies can be asynchronously loaded.

Definition

An AMD environment provides a single global function, define.

The define function accepts as parameters:

  • an array of module ids (that specify the dependency)
  • and a factory function that returns values in order to export (made public) any JavaScript type (function, constructor, object)

Example

define(['my-dependency'], function(MyDependency) {
  return function() {};
});

Test AMD environment

console.log("Is this an AMD environment ? "+(typeof define === 'function' && define.amd))

Documentation / Reference


Powered by ComboStrap