What Is AMD module?
The AMD is stands for Asynchronous Module Definition and is used for defining modules and their dependencies with asynchronously manner.
Defining Modules -The Module is defined using define () method and it used for loading the module i.e.
define({
country:"India",
state: "UP",
city: "Noida",
userDetail: function () {
return "User Detail";
}
});
Defining Functions - A module can also use a function without dependencies i.e.
define(function () {
return {
country:"India",
state: "UP",
city: "Noida"
}
});
Defining Functions with Dependencies - The Dependencies module looks like.
define(["../comp", "../user"],
function(comp, user) {
return {
country:"India",
state: "UP",
city: "Noida",
addUser: function() {
comp.decrement(this);
user.add(this);
}
}
});
Defining a Module as a Function - Its looks like.
define(["../comp", "../user"],
function(comp, user) {
return function(userName){
return userName != null ? userName :'NA'
}
});
Defining a Module with a Name - Its looks like.
define("Users", ["../comp", "../user"],
function(comp, user) {
return {
country:"India",
state: "UP",
city: "Noida",
addUser: function() {
console.log(this);
}
}
});
I hope you are enjoying with this post! Please share with you friends!! Thank you!!!