Javascript - Asynchronous Module Definition (AMD)

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript)

1 - About

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

Advertising

3 - 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)

4 - Example

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

5 - Test AMD environment

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

6 - Documentation / Reference

web/javascript/amd.txt · Last modified: 2019/02/16 17:40 by gerardnico