modern-javascript-patterns
它能做什么
这份指南教你如何使用最新版本的 JavaScript(即 ES6+)编写更简洁、更高效、更易读的代码,涵盖 async/await、解构赋值等特性。
适用场景
- ✓你手里有旧的 JavaScript 代码,想要更新时。
- ✓想让代码结构更清晰、更易读时。
- ✓需要处理耗时操作,比如从网络获取数据时。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/javascript-typescript/skills/modern-javascript-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何把这段旧的 JavaScript 代码更新为使用现代特性?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会参考指南中的最佳实践和示例,帮你改写代码。重点是运用 JavaScript 的新特性,让代码更高效、更易读。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Modern JavaScript Patterns
Comprehensive guide for mastering modern JavaScript (ES6+) features, functional programming patterns, and best practices for writing clean, maintainable, and performant code.
When to Use This Skill
- Refactoring legacy JavaScript to modern syntax
- Implementing functional programming patterns
- Optimizing JavaScript performance
- Writing maintainable and readable code
- Working with asynchronous operations
- Building modern web applications
- Migrating from callbacks to Promises/async-await
- Implementing data transformation pipelines
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Use const by default: Only use let when reassignment is needed
- Prefer arrow functions: Especially for callbacks
- Use template literals: Instead of string concatenation
- Destructure objects and arrays: For cleaner code
- Use async/await: Instead of Promise chains
- Avoid mutating data: Use spread operator and array methods
- Use optional chaining: Prevent "Cannot read property of undefined"
- Use nullish coalescing: For default values
- Prefer array methods: Over traditional loops
- Use modules: For better code organization
- Write pure functions: Easier to test and reason about
- Use meaningful variable names: Self-documenting code
- Keep functions small: Single responsibility principle
- Handle errors properly: Use try/catch with async/await
- Use strict mode:
'use strict'for better error catching
For common pitfalls (this binding, promise anti-patterns, memory leaks), see references/advanced-patterns.md.
常见问题
什么是 “ES6+”?
这是 JavaScript 语言的较新版本,带来了许多改进和新特性,让程序员的工作更轻松。
什么是 async/await?
这是一种更简单的处理耗时任务的方式,比如从网络下载信息,同时不会阻塞程序其他部分的运行。
什么是“重构代码”?
重构就是在不改变代码功能的前提下,重新编写现有代码以使其更好。就像打扫房间,把东西收拾整齐,但不挪动家具。
详情
作者的原始描述
Master ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional programming patterns for writing clean, efficient JavaScript code. Use when refactoring legacy code, implementing modern patterns, or optimizing JavaScript applications.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6713
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …