关于 clean-codejs-objects
面向 JavaScript 开发者的对象与类设计技能,介绍封装、不可变性和内聚性等模式。
主要功能
- 01通过方法实现封装
- 02不可变更新模式
- 03类设计中的内聚性
适用场景
- 01避免直接修改对象字段
- 02设计内聚的类
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ damianwrooby/ javascript-clean-code-skills --skill clean-codejs-objects安装后在 Claude Code 中输入/clean-codejs-objects确认已加载。
README 原文English
来自项目 READMEREADME 暂无中文译文,以下为英文原文;中文介绍见上方。
Clean Code JavaScript – Object & Class Patterns
Table of Contents
- Encapsulation
- Immutability
- Cohesion
Encapsulation
// ❌ Bad
user.name = 'John';
// ✅ Good
user.rename('John');
Immutability
// ❌ Bad
user.age++;
// ✅ Good
const updatedUser = user.withAge(user.age + 1);
Cohesion
// ❌ Bad
class User {
calculateTax() {}
}
// ✅ Good
class TaxCalculator {
calculate(user) {}
}
评论
支持 Markdown