The front-end es6 is a modular development; the es6 modular specification is a modular development specification common to the browser and server, which defines that each JavaScript file is an independent module and can be imported into other module members for use The import keyword and the export keyword are used to share module members externally.
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
ES6 modular specification is a common modular development specification for browser side and server side. Its emergence has greatly reduced the modular learning costs of front-end developers. Developers do not need to learn additional modular specifications such as AMD (AMD yes!!! XD), CMD or CommonJS.
ES6 modularization specification defines:
Each js file is an independent module
Use the import keyword to import other module members
Use the export keyword to share module members externally
Experience ES6 modularization in node.js
Make sure v14.15.1 or higher is installed Version of node.js
Add "type": "module" node to the root node of package.json
Default export and default Import
Export default can only be used once in each js script, otherwise an error will be reported
// 默认导出 // 每个js脚本里面只能使用唯一一次 export default ,否则会报错 let m1 = 10 let m2 = 20 let f1 = () =>{} export default { m1, f1 }
// 默认导入 // 路径务必将文件后缀写上 import i1 from './01.默认导出.js' console.log(i1)
[Related recommendations:javascript Video tutorial、web front-end】
The above is the detailed content of Is front-end es6 modular development?. For more information, please follow other related articles on the PHP Chinese website!