AGENT SKILL
JavaScript Best Practices
Idiomatic JavaScript patterns and conventions for maintainable code.
适用职业开发工程师
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 66
- Forks
- 24
01 前言 Front Matter
- name
- JavaScript Best Practices
- metadata
- { "labels": [ "javascript", "best-practices", "conventions", "code-quality" ], "triggers": { "files": [ "**/*.js", "**/*.mjs" ], "keywords": [ "module", "import", "export", "error", "validation" ] } }
- description
- Idiomatic JavaScript patterns and conventions for maintainable code.
02 资源文件 14
- 许可证LICENSE.txt1.0 KB
- 参考文档references/advisor-template.md2.1 KB
- 参考文档references/advisors/alex-hormozi.md3.9 KB
- 参考文档references/advisors/ann-handley.md4.0 KB
- 参考文档references/advisors/april-dunford.md4.3 KB
- 参考文档references/advisors/byron-sharp.md4.7 KB
- 参考文档references/advisors/claude-hopkins.md3.7 KB
- 参考文档references/advisors/david-ogilvy.md4.0 KB
- 参考文档references/advisors/eugene-schwartz.md4.1 KB
- 参考文档references/advisors/gary-halbert.md3.9 KB
- 参考文档references/advisors/gary-vaynerchuk.md4.3 KB
- 参考文档references/advisors/rory-sutherland.md4.6 KB
- 参考文档references/advisors/russell-brunson.md4.2 KB
- 参考文档references/advisors/seth-godin.md3.9 KB
03 SKILL.md 正文
JavaScript Best Practices
Priority: P1 (OPERATIONAL)
Conventions and patterns for writing maintainable JavaScript.
Implementation Guidelines
- Naming:
camelCase(vars/funcs),PascalCase(classes),UPPER_SNAKE(constants). - Errors: Throw
Errorobjects only. Handle all async errors. - Comments: JSDoc for APIs. Explain "why" not "what".
- Files: One entity per file.
index.jsfor exports. - Modules: Named exports only. Order: Ext -> Int -> Rel.
Anti-Patterns
- No Globals: Encapsulate state.
- No Magic Numbers: Use
const. - No Nesting: Guard clauses/early returns.
- No Defaults: Use named exports.
- No Side Effects: Keep functions pure.
Code
// Constants
const STATUS = { OK: 200, ERROR: 500 };
// Errors
class APIError extends Error {
constructor(msg, code) {
super(msg);
this.code = code;
}
}
// Async + JDoc
/** @throws {APIError} */
export async function getData(id) {
if (!id) throw new APIError('Missing ID', 400);
const res = await fetch(`/api/${id}`);
if (!res.ok) throw new APIError('Failed', res.status);
return res.json();
}
Reference & Examples
For module patterns and project structure: See references/REFERENCE.md.
Related Topics
language | tooling