跳到正文
Skillpedia
通用编程41k · #6713

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/wshobson/agents/blob/main/plugins/javascript-typescript/skills/modern-javascript-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  1. Use const by default: Only use let when reassignment is needed
  2. Prefer arrow functions: Especially for callbacks
  3. Use template literals: Instead of string concatenation
  4. Destructure objects and arrays: For cleaner code
  5. Use async/await: Instead of Promise chains
  6. Avoid mutating data: Use spread operator and array methods
  7. Use optional chaining: Prevent "Cannot read property of undefined"
  8. Use nullish coalescing: For default values
  9. Prefer array methods: Over traditional loops
  10. Use modules: For better code organization
  11. Write pure functions: Easier to test and reason about
  12. Use meaningful variable names: Self-documenting code
  13. Keep functions small: Single responsibility principle
  14. Handle errors properly: Use try/catch with async/await
  15. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能