关于 clean-codejs-functions
clean-codejs-functions 是面向开发者的 JavaScript 函数设计实践技能,涵盖单一职责、函数规模、参数组织和副作用控制。
主要功能
- 01函数遵循单一职责
- 02函数规模指导
- 03使用对象组织参数
- 04减少副作用
适用场景
- 01拆分承担多项职责的函数
- 02保持 JavaScript 函数简短
- 03组织相关函数参数
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ damianwrooby/ javascript-clean-code-skills --skill clean-codejs-functions安装后在 Claude Code 中输入/clean-codejs-functions确认已加载。
README 原文English
来自项目 READMEREADME 暂无中文译文,以下为英文原文;中文介绍见上方。
Clean Code JavaScript – Function Patterns
Table of Contents
- Single Responsibility
- Function Size
- Parameters
- Side Effects
Single Responsibility
// ❌ Bad
function handleUser(user) {
saveUser(user);
sendEmail(user);
}
// ✅ Good
function saveUser(user) {}
function notifyUser(user) {}
Function Size
Keep functions small (ideally < 20 lines).
Parameters
// ❌ Bad
function createUser(name, age, city, zip) {}
// ✅ Good
function createUser({ name, age, address }) {}
Side Effects
// ❌ Bad
let total = 0;
function add(value) {
total += value;
}
// ✅ Good
function add(total, value) {
return total + value;
}
评论
支持 Markdown