模块化标准及 ES Modules 支持情况
一、模块化标准与规范
CommonJS
简介:CommonJS 是最早的 JavaScript 模块化标准,主要用于服务端(如 Node.js)。
特点:
使用 require 导入模块,使用 module.exports 或 exports 导出模块。
模块是同步加载的,这在服务器环境中是合理的。
示例:
// module.js
const greeting = 'Hello, World!';
module.exports = greeting;
// app.js
const greeting = require('./module');
console.log(greeting); // Hello, World!
https://www.nowcoder.com/issue/tutorial?zhuanlanId=j572L2&uuid=34f94c51e98c43189698d5dbb201f92c
CommonJS
简介:CommonJS 是最早的 JavaScript 模块化标准,主要用于服务端(如 Node.js)。
特点:
使用 require 导入模块,使用 module.exports 或 exports 导出模块。
模块是同步加载的,这在服务器环境中是合理的。
示例:
// module.js
const greeting = 'Hello, World!';
module.exports = greeting;
// app.js
const greeting = require('./module');
console.log(greeting); // Hello, World!
https://www.nowcoder.com/issue/tutorial?zhuanlanId=j572L2&uuid=34f94c51e98c43189698d5dbb201f92c
全部评论
相关推荐
07-22 09:09
河南科技学院 Java 
点赞 评论 收藏
分享