Friday, August 23, 2019

AMD

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 defineand 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 {
        sayHi: function(){
            console.log('Hi there!')
        }
    }
});
In the preceding code, we are passing three arguments to the global define method, which has been provided to us by an AMD-compatible module loader.

https://subscription.packtpub.com/book/web_development/9781785880650/10/ch10lvl1sec54/introducing-asynchronous-module-definition

No comments:

Followers

Link