python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
How to Install RequireJS?

When Should I use Require() and when to use Define()? [Require vs Define]

The define () method looks like -
ü  The define () method is used for facilitating module definition
ü  The define () method accepts two optional parameters module ID and array of required modules [dependencies]
ü  The define() method MUST return the implementation for your module i.e.

  module_id /*optional*/,
  definition function /*function for instantiating the module or object*/

define(['moduleA''moduleB'], function (moduleAmoduleB) {
  //define the module value by returning a value
  return function () {};

The require () method looks like -
ü  The require () method is used for handling dependency loading
ü  The require () function doesn't have to return the implementation of a new module.

require(['jquery'], function ($) {
  //jQuery was loaded and can be used now.

Example 1 -
define'MyApp', ["marionette"], function (Marionette) {
      // set up the app instance
      var app = new Marionette.Application();
        console.log("initialize started.");

      // export the app from this module
      return app;

Example 2 -
// Fetch and execute Marionette App
require( ["MyApp"], function (app) {
  // Execute App

Example 3 -
  "root": {
     "india": "india",
     "australia": "australia",
     "england": "england"

I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions