模块化标准及 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
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务