Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Latest commit

 

History

History

src

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Require.js Steps (pt-Br)

  • 00 - without require.js

avoid, bad practice, everything is global

var att = 'some att value';

function logic() {
  return 'something';
}
  • 01 - without require.js, js app with namespaces

good practice, nothing is directly global

(function(global, undefind) {

  // main app namespace
  var app = global.app = global.app || {};

  // private

  var att = 'some att value';

  function logic() {
    return 'something';
  }

  // public - local namespace
  app.localNamespace = {
    att: att,
    logic: logic
  };

})(window);
  • 02 - AMD Style

Require.js code style

// AMD Style
define(['myDependency'], function(myDependency) {  

  // private

  return {
    /* public */
  };
});
  • 03 - CommonJS Style

Node.js code style

// CommonJS Style
define(function(require) {

  // private

  var myDependency = require('myDependency');

  return {
    /* public */
  };
});