Tutorial by Examples

The UMD (Universal Module Definition) pattern is used when our module needs to be imported by a number of different module loaders (e.g. AMD, CommonJS). The pattern itself consists of two parts: An IIFE (Immediately-Invoked Function Expression) that checks for the module loader that is being i...
Immediately invoked function expressions can be used to create a private scope while producing a public API. var Module = (function() { var privateData = 1; return { getPrivateData: function() { return privateData; } }; })(); Module.getPrivateData(); // 1 Module.priva...
AMD is a module definition system that attempts to address some of the common issues with other systems like CommonJS and anonymous closures. AMD addresses these issues by: Registering the factory function by calling define(), instead of immediately executing it Passing dependencies as an array...
CommonJS is a popular modularization pattern that's used in Node.js. The CommonJS system is centered around a require() function that loads other modules and an exports property that lets modules export publicly accessible methods. Here's an example of CommonJS, we'll load Lodash and Node.js' fs m...
6 In ECMAScript 6, when using the module syntax (import/export), each file becomes its own module with a private namespace. Top-level functions and variables do not pollute the global namespace. To expose functions, classes, and variables for other modules to import, you can use the export keyword....

Page 1 of 1