small pieces that can work independently. You can then assemble or reorganize these blocks of code (like Lego) and create a variety of different applications from the same set of modules.Since the module is very useful, there have been several attempts to add module functionality to JavaScript in history. Today, two modular systems are being used on a wide scale. CommonJS (CJS) is used in the history of node. js. The ESM (EcmaScript module) is an upd
Module specification of COMMONJS
The relationship between node and browser, as well as the organization of the COMMONJS, the ECMAScriptNode uses COMMONJS's modules specification to realize a set of modular system, so first look at the COMMONJS module specification.Commonjs The module definition is very simple, mainly divided into module reference, module definit
modular specifications have been introduced to address the need for asynchronous, modular programming on the browser side, and the core principle is to load modules asynchronously by dynamically loading script and event snooping; __
AMD and CMD are the most representative of the two works corresponding to Require.js and Sea.js, the main difference is the time to rely on the declaration and dependency loading, where require.js by default in the declaration, sea.js respected lazy loading and on-d
I previously in the "Front end of the environment from the beginning to give up" this article spit, Webpack can write COMMONJS format require synchronization syntax, can write the AMD format require callback syntax, There is also a require.ensure, and webpack own definition of require.include, plus ES6 import grammar, so many will not confuse people. This article will be to comb the characteristics of these require, and in what scenarios are used.COMM
Use require to load jslite, Zepto, and jquery methods, which are the same type of libraries so they are loaded, and here is an instance.Requirejs Reference instance methodThe goal of Requirejs is to encourage the modularity of code, which uses a script loading step that differs from the traditional Extend-jslite.jsDefine ([' Lib/jslite '], function (a) {"Use strict";Window. Jslite = JsliteIf ' $ ' or ' jQuery ' isn't yet defined, point them to ' jslite '' $ ' in window | | (window.$ = jslite)' J
This article mainly introduces Node. module mechanism learning notes in js. This article describes CommonJS module specifications, Node module implementation process, module call stack, packages, and NPM. For more information, see Javascript, no one once considered it a programming language. In the Web 1.0 era, this scripting language is mainly used for Form Verification and webpage special effects. It was not until the Web 2.0 era that front-end engi
This article mainly introduces require. js in-depth understanding, require. js features. This article describes require. javaScript and CommonJS are compatible, CDN rollback, cyclic dependency, BaseUrl, and JSONP. For more information, see Require. js is my favorite Javascript programming method. It can reduce code to zero and facilitate management. The Require. js Optimizer can help us to scatter a large application into multiple small applications,
"Cyclic loading" (circular dependency) means that the execution of a script relies on the B script, while the execution of the B script relies on a script.
A.js
var b = require (' B ');
B.js
var a = require (' a ');
In general, "cyclic loading" means strong coupling, which, if poorly handled, can also result in recursive loading that prevents the program from executing and should therefore be avoided.
But in fact, this is very difficult to avoid, especially the complex dependencie
Require. js: a deep understanding of require. js features
Now, Require. js is my favorite Javascript programming method. It can reduce code to zero and facilitate management. The Require. js Optimizer can help us to scatter a large application into multiple small applications, connect them through dependencies, and finally combine them during compilation and packaging. These reasons prompted us to use require. js.
So, let's take a look at the awesome features of require. js!
Compatible with
line, the entire product from scratch, are to be controlled by the pipeline, in the assembly line we can manage the product." ”In addition, Gulp is built through a task for the entire development process.WebpackWebpack is now the most popular modular management and packaging tool for front-end resources. It can package many loose modules according to dependencies and rules into front-end resources that meet the deployment of the production environment. You can also code-separate modules that ar
Webpack can write the COMMONJS format of the Require synchronization syntax, you can write the require callback syntax in AMD format, There is also a require.ensure, and webpack own definition of require.include, plus ES6 import grammar, so many will not confuse people. This article will be to comb the characteristics of these require, and in what scenarios are used.COMMONJS synchronization SyntaxThe classic COMMO
the path relative to the component), and is completelyCompatible with CommonJS specifications on Component ID formats.
CommonJS conventions on Component IDs:
L The component ID is composed of words separated by commas (,). Each word must be in the camper format, or it can be '.' or '..' to indicate the relative relationship;
L The component ID can have a suffix of '. js' or a suffix of'. js;
Example:
Assum
I previously in the "Front end of the environment from the beginning to give up" this article spit, Webpack can write COMMONJS format require synchronization syntax, can write the AMD format require callback syntax, There is also a require.ensure, and webpack own definition of require.include, plus ES6 import grammar, so many will not confuse people. This article will be to comb the characteristics of these require, and in what scenarios are used.COMM
is, in fact, only after Webpack analyzes your source code, it makes some modifications to it, and then organizes all the source code in one file. Finally, a large bundle JS file is generated and executed by the browser or other Javascript Engines and the result is returned.
Here is a simple case to illustrate the principles of the Webpack packaging module. For example, we have a module named mA. js.
var aa = 1;function getDate() { return new Date();}module.exports = { aa: aa, getDate: getDate}
PDF version of the PPT download address: http://www.slideshare.net/jibyjohnc/jqquerysummit-largescale-javascript-application-architecture
Note: In the process of finishing, found that some of the author's thoughts are back to say, so the deletion of a part, if your English is good, please read the English ppt directly.
The following are the main chapters of this article:
1. What is called "JavaScript large program"?
2. Look at the current program structure
3. Long-term consideration
4. Bra
So, let's see what the require.js has to do with it!Compatible with COMMONJS
AMD (Asynchronous Module definition specification) appears from the COMMONJS workgroup. COMMONJS is designed to create javascript ecosystems. An important part of COMMONJS is TRANSPORT/C, the predecessor of AMD, and Require.js is an implement
JavaScript basic Discipline (4) Code deduction for--UMD Specification 1. UMD specification
Address: GITHUB.COM/UMDJS/UMD
UMDSpecification, is the most ugly one in all specifications, no one!!! It is designed to allow modules to be compatible AMD and regulated, and is used by a CommonJs number of third-party libraries that require both browser-side and server-side references. UMDis the product of an era, and ES harmony it will also exit the historical
Node. js module mechanism learning notes, node. js learning notes
Javascript has never been used as a programming language since its birth. In the Web 1.0 era, this scripting language is mainly used for Form Verification and webpage special effects. It was not until the Web 2.0 era that front-end engineers used it to greatly improve the user experience on the Web page that JavaScript was widely valued. As JavaScript gradually becomes popular, it has gone through changes in tool libraries, Compon
RequirejsJavaScript Modular Programming (AMDCOMMONJS)The notation of the moduleViewAMD SpecificationsCurrently, there are two types of common JavaScript module specifications: CommonJS and AMD .In Commonjs, there is a global method require () that is used to load the module. Assuming that a mathematical module is math.js, it can be loaded as follows.var math = require(‘math‘);Then, you can invoke the method
, see the above two articles.
The most famous one is expressjs.
Remember, when you see these js frameworks, you smile and write the mvc Framework Based on nodejs:
Sails. js, Total. js, Partial. js, Koa. js, Locomotive. js, Express. js, Flatiron. js
[Js modularization]
Related Concepts: commonjs, amd, cmd, umd
Related frameworks: commonjs, seajs, requirejs, and coolie
Similar to Java: import, or import ..
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.