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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^