Modern Javascript Patterns

作者 wshobson46891e7e60da無授權條款收錄於 2026年10月8日更新於 2026年10月8日

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.

AI 產生的概覽

指導使用現代 ES6+ 語法、非同步模式與函式式程式設計實務來撰寫與重構 JavaScript。

功能
提供現代 JavaScript 功能的參考指南,包括 async/await、解構、展開運算子、箭頭函式、Promise、模組、迭代器、產生器和函式式程式設計模式。它列出撰寫整潔、可維護程式碼的最佳實務,並指向隨附的參考檔案,其中包含詳細模式、範例和常見陷阱。產出的是指引與範例,而非可執行的結果。
適用情境
適用於將舊式 JavaScript 重構為現代語法、把回呼遷移到 Promise 或 async/await,或實作函式式與資料轉換模式。也適合在最佳化 JavaScript 效能或統一可讀性與可維護性規範時使用。
執行需求
無需執行環境、套件或憑證;僅為說明與參考文件,不含指令碼。

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 [blocked].

來源與署名

來源:wshobson/agents位於plugins/javascript-typescript/skills/modern-javascript-patterns提交46891e7

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架