1 Overview
Are often faced with the traditional development model of a number of issues, such as naming conflicts, file dependence, it is necessary to solve the problem through modularity.
Modular: is a function of the individual encapsulated into a module, isolation between modules, but can be disclosed through a specific internal members interfaces, may be dependent on other modules.
Benefits: to facilitate code reuse, which commission the development efficiency, and easy ongoing maintenance.
2. The browser modular specification
AMD typical representatives Require.js
CMD typical representatives Sea.js
3. The modular server specifications
CommonJS
- Into a single module and file module package
- Export module members: module.exports and exports
- Import module members: the require ( 'module identifier')
Modular 4.ES6
Prerequisite: Before ES6 modular specification birth, Javascript attempt to raise community although AMD, CMD, and CommonJS and other modular specification, but because of their own there are some differences and limitations, not the browser and server versatile modular standard ,E.g:
- AMD and CMD only applies to browser-side Javascript modular
- CommonJS only applies to server-side Javascript modular
Therefore, the definition of the ES6 modular specification, is browser and server versatile modular development specifications.
ES6 modular specification defines:
- Every JS file is a separate module
- Import module members to use import keywords
- Exposure module members to use export keyword