Skip to content

模块

一句话解释

模块是 self-包含单元的 code 那个能 是 imported and reused 通过 other 部分的 program.

用大白话说

A module is a file (or group of files) that contains related code — functions, classes, variables — organized together and made available to other files through imports. Modules help you break a large program into manageable pieces.

Instead of writing everything in one giant file, you split your code into modules: a math module for calculations, a ui module for interface, a 数据库 module for data access. Each module has a clear responsibility and can be developed and tested independently.

Modules also control visibility. You explicitly 导出 the parts you want to share and keep everything else private. This prevents naming collisions and makes dependencies explicit. JavaScript uses 导入/导出, Python uses 导入, and Java uses 包/导入.

示例

javascript
// math.js
export function add(a, b) { return a + b; }
export function multiply(a, b) { return a * b; }

// main.js
import { add, multiply } from './math.js';
console.log(add(2, 3));      // 5
console.log(multiply(4, 5)); // 20

math 模块导出添加 and multiply. 主要.js 导入 and uses 它们. 模块's 内部 details 是隐藏.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表