mcpField
C
clean-codejs-objects

clean-codejs-objects

github.com/damianwrooby开发079 次安装39 周前更新
代码仓库

关于 clean-codejs-objects

面向 JavaScript 开发者的对象与类设计技能,介绍封装、不可变性和内聚性等模式。

主要功能

  1. 01通过方法实现封装
  2. 02不可变更新模式
  3. 03类设计中的内聚性

适用场景

  1. 01避免直接修改对象字段
  2. 02设计内聚的类

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/damianwrooby/javascript-clean-code-skills --skill clean-codejs-objects

安装后在 Claude Code 中输入/clean-codejs-objects确认已加载。

README 原文English

来自项目 README

README 暂无中文译文,以下为英文原文;中文介绍见上方。

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