Asynchronous Module Definition (AMD) Modules

What Are AMD Modules In RequireJS?

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(compuser) {
      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(compuser) {
      return function(userName){
          return userName != null ? userName :'NA'
      }
});

Defining a Module with a Name - Its looks like.
define("Users", ["../comp""../user"],
  function(compuser) {
    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!!!
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - https://code-sample.com and https://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions