clean-codejs-comments
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClean Code JavaScript – Comment Patterns
整洁代码 JavaScript – 注释模式
Table of Contents
目录
- When to Comment
- When Not to Comment
- Examples
- 何时添加注释
- 何时无需添加注释
- 示例
When to Comment
何时添加注释
- Explain why, not what
- Document complex business rules
- 解释原因,而非内容
- 记录复杂的业务规则
When Not to Comment
何时无需添加注释
- Obvious code
- Outdated explanations
- 显而易见的代码
- 过时的解释
Examples
示例
js
// ❌ Bad
// Increment i by 1
i++;
// ✅ Good
// Retry once to handle flaky network condition
retryRequest();js
// ❌ 不佳
// 将i自增1
i++;
// ✅ 良好
// 重试一次以处理不稳定的网络状况
retryRequest();