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.define('moduleOneId', ['dependency'], function(dependency) {
return {
sayHi: function(){
console.log('Hi there!')
}
}
});
In the preceding code, we are passing three arguments to the global
https://subscription.packtpub.com/book/web_development/9781785880650/10/ch10lvl1sec54/introducing-asynchronous-module-definition
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:
Post a Comment