enoyao

JavaScript

開發程式設計v1.0.2
作者:enoyao更新於 2026-05-11共 3 個版本 · 最新版本釋出於 2026-03-18javascript-skills@clawhub_wscats/javascript-skills
程式碼生成程式碼審查#Javascript

據 AlphaMoat 統計,截至 2026-10,JavaScript 累計下載 9,327 次、獲 14 個星標,按累計下載量在本次參與排名的 10,914 個 AI 技能中排名第 2,953 位,在「開發程式設計」分類(1,069 個)中排名第 230 位。

列表預設按累計下載量排序,也可按星標排序;詳情頁排名按累計下載量計算。

累計下載
9327
星標
14
全站下載量排名
#2,953
全站前 28% · 「開發程式設計」前 22%
平台累計下載星標評論
ClawHub ↗777711-
SkillHub ↗932714—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

提及或涉及 JavaScript 時啟用。風格規則涵蓋變數與引用、物件和陣列、解構、字串、函式、箭頭函式、類、ES modules、迭代、屬性訪問、錯誤處理與命名。偏好 const,需要重賦值時用 let,避免 var;優先使用嚴格相等 ===/!==,使用 parseInt 時必須提供 radix。還強調一致的縮排、尾隨逗號和分號。

資料釋出於 2026-10-27

可以用來做什麼

  • 提供符合約定的 JavaScript 程式碼與風格解釋。

什麼時候用

  • 使用者提到 JavaScript,或要求審查、編寫、重構 JavaScript 程式碼時使用。

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

按該指南重構這段 JavaScript,並說明主要風格選擇。

月度資料趨勢

累計下載9327
5059735196432026-03 · 累計下載 53752026-05 · 累計下載 66702026-06 · 累計下載 68602026-07 · 累計下載 71312026-08 · 累計下載 73902026-09 · 累計下載 79802026-10 · 累計下載 932726-0326-0926-10
星標14
410152026-03 · 星標 52026-05 · 星標 112026-06 · 星標 112026-07 · 星標 132026-08 · 星標 142026-09 · 星標 142026-10 · 星標 1426-0326-0926-10

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。 該技能有同名的其他版本,調整前的資料歸屬當前下載量最大的這一個。

月份累計下載環比星標
2026-109327—14
2026-097980—14
2026-087390+3.6%14
2026-077131+4.0%13
2026-066860+2.8%11
2026-056670—11
2026-035375—5

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

17 KB · ClawHub v1.0.2
---
name: JavaScript
license: MIT
description: >
  A comprehensive JavaScript style guide skill.
  When activated, it provides best-practice JavaScript coding conventions and generates
  code that strictly follows the style guide, covering variables, functions, objects,
  arrays, classes, modules, async patterns, error handling, naming conventions, and more.
---
展開全部(共 747 行)
# JavaScript Style Guide Skill

## Activation

This skill activates when the user mentions or implies **JavaScript** in their request. Once activated, it:

- Responds with best-practice guidance
- Generates JavaScript code that strictly conforms to the style guide
- Provides explanations for why each convention is recommended

---

## Complete Style Rules

### 1. References

- Use `const` for all references; avoid `var`.
- If you must reassign references, use `let` instead of `var`.
- Both `const` and `let` are block-scoped, whereas `var` is function-scoped.

```javascript
// bad
var count = 1;

// good
const count = 1;
let mutableValue = 1;
mutableValue += 1;
```

### 2. Objects

- Use literal syntax for object creation.
- Use computed property names when creating objects with dynamic property names.
- Use object method shorthand and property value shorthand.
- Group shorthand properties at the beginning of the object declaration.
- Only quote properties that are invalid identifiers.
- Prefer the object spread syntax (`...`) over `Object.assign` to shallow-copy objects.

```javascript
// bad
const item = new Object();

// good
const item = {};

// computed property names
const key = 'name';
const obj = { [key]: 'value' };

// method & property shorthand
const name = 'Alice';
const atom = {
  name,
  value: 1,
  addValue(val) {
    return atom.value + val;
  },
};

// shallow copy
const original = { a: 1, b: 2 };
const copy = { ...original, c: 3 };
```

### 3. Arrays

- Use literal syntax for array creation.
- Use `Array.from` or the spread operator to convert array-like objects.
- Use `return` statements in array method callbacks.
- Use line breaks after the opening bracket and before the closing bracket if the array has multiple lines.

```javascript
// bad
const items = new Array();

// good
const items = [];

// convert iterable
const nodes = Array.from(document.querySelectorAll('.item'));
const uniqueValues = [...new Set(arr)];

// array methods
[1, 2, 3].map((x) => x + 1);

[1, 2, 3].map((x) => {
  const y = x + 1;
  return x * y;
});
```

### 4. Destructuring

- Use object destructuring when accessing multiple properties of an object.
- Use array destructuring.
- Use object destructuring for multiple return values, not array destructuring.

```javascript
// bad
function getFullName(user) {
  const firstName = user.firstName;
  const lastName = user.lastName;
  return `${firstName} ${lastName}`;
}

// good
function getFullName({ firstName, lastName }) {
  return `${firstName} ${lastName}`;
}

// array destructuring
const [first, , third] = [1, 2, 3];

// multiple return values — use object destructuring
function processInput(input) {
  return { left, right, top, bottom };
}
const { left, top } = processInput(input);
```

### 5. Strings

- Use single quotes `''` for strings.
- Use template literals for string interpolation and multi-line strings.
- Never use `eval()` on a string.
- Do not unnecessarily escape characters in strings.

```javascript
// bad
const name = "Alice";
const greeting = 'Hello, ' + name + '!';

// good
const name = 'Alice';
const greeting = `Hello, ${name}!`;
```

### 6. Functions

- Use named function expressions instead of function declarations.
- Wrap immediately invoked function expressions (IIFE) in parentheses.
- Never declare a function in a non-function block (`if`, `while`, etc.).
- Never name a parameter `arguments`.
- Use default parameter syntax rather than mutating function arguments.
- Always put default parameters last.
- Never use the `Function` constructor to create a new function.
- Use the spread operator `...` to call variadic functions.
- Use rest parameters (`...args`) instead of `arguments`.

```javascript
// named function expression
const short = function longUniqueMoreDescriptiveLexicalFoo() {
  // ...
};

// default parameters last
function handleThings(name, opts = {}) {
  // ...
}

// rest parameters
function concatenateAll(...args) {
  return args.join('');
}

// spread to call
const values = [1, 2, 3];
console.log(Math.max(...values));
```

### 7. Arrow Functions

- Use arrow function notation for anonymous functions (callbacks).
- If the function body consists of a single expression, omit the braces and use the implicit return.
- If the expression spans multiple lines, wrap it in parentheses for readability.
- Always include parentheses around arguments for clarity and consistency.

```javascript
// bad
[1, 2, 3].map(function (x) {
  const y = x + 1;
  return x * y;
});

// good
[1, 2, 3].map((x) => {
  const y = x + 1;
  return x * y;
});

// implicit return
[1, 2, 3].map((x) => x * 2);

// multiline implicit return
[1, 2, 3].map((number) => (
  `A long string with the ${number}. It's so long that we don't want it to take up space on the .map line!`
));
```

### 8. Classes & Constructors

- Always use `class`; avoid manipulating `prototype` directly.
- Use `extends` for inheritance.
- Methods can return `this` to enable method chaining.
- Classes have a default constructor if no constructor is specified; an empty constructor or one that just delegates to a parent is unnecessary.
- Avoid duplicate class members.

```javascript
// bad
function Queue(contents = []) {
  this.queue = [...contents];
}
Queue.prototype.pop = function () {
  return this.queue.pop();
};

// good
class Queue {
  constructor(contents = []) {
    this.queue = [...contents];
  }

  pop() {
    return this.queue.pop();
  }
}

// inheritance
class PeekableQueue extends Queue {
  peek() {
    return this.queue[0];
  }
}
```

### 9. Modules

- Always use ES modules (`import`/`export`) over a non-standard module system.
- Do not use wildcard imports.
- Do not export directly from an import.
- Only import from a path in one place.
- Do not export mutable bindings.
- Prefer default export for modules that only export a single thing.
- Put all `import`s above non-import statements.
- Multi-line imports should be indented like multi-line array and object literals.

```javascript
// bad
const utils = require('./utils');
module.exports = utils.fetchData;

// good
import { fetchData } from './utils';
export default fetchData;

// single place import
import { named1, named2 } from 'module';

// multiline
import {
  longNameA,
  longNameB,
  longNameC,
} from 'path/to/module';
```

### 10. Iterators and Generators

- Prefer JavaScript's higher-order functions over `for-in` or `for-of` loops.
- Use `map`, `filter`, `reduce`, `find`, `findIndex`, `every`, `some`, etc.
- Don't use generators for now (if targeting ES5 environments).

```javascript
const numbers = [1, 2, 3, 4, 5];

// bad
let sum = 0;
for (const num of numbers) {
  sum += num;
}

// good
const sum = numbers.reduce((total, num) => total + num, 0);

// filtering
const evens = numbers.filter((num) => num % 2 === 0);
```

### 11. Properties

- Use dot notation when accessing properties.
- Use bracket notation `[]` when accessing properties with a variable.
- Use the exponentiation operator `**` instead of `Math.pow`.

```javascript
const luke = { jedi: true, age: 28 };

// dot notation
const isJedi = luke.jedi;

// bracket notation
const prop = 'jedi';
const isJedi = luke[prop];

// exponentiation
const result = 2 ** 10;
```

### 12. Variables

- Always use `const` or `let`; never use `var`.
- Use one `const` or `let` declaration per variable or assignment.
- Group all `const`s and then group all `let`s.
- Assign variables where you need them, but place them in a reasonable place.
- Don't chain variable assignments.
- Avoid using unary increments (`++`, `--`); use `+= 1` / `-= 1` instead.
- Avoid linebreaks before or after `=` in an assignment.

```javascript
// bad
const items = getItems(),
  goSportsTeam = true,
  dragonball = 'z';

// good
const items = getItems();
const goSportsTeam = true;
const dragonball = 'z';

// group const then let
const a = 1;
const b = 2;
let c = 3;
let d = 4;

// avoid unary
let count = 0;
count += 1;
```

### 13. Hoisting

- `var` declarations get hoisted; `const` and `let` are in Temporal Dead Zone.
- Named function expressions hoist the variable name but not the function body.
- Function declarations hoist the name and the function body.

### 14. Comparison Operators & Equality

- Use `===` and `!==` over `==` and `!=`.
- Use shortcuts for booleans, but explicit comparisons for strings and numbers.
- Use braces to create blocks in `case` and `default` clauses that contain lexical declarations.
- Ternaries should not be nested and generally be single-line expressions.
- Avoid unneeded ternary statements.
- When mixing operators, enclose them in parentheses (except `**`, `+`, `-`).

```javascript
// bad
if (isValid == true) { /* ... */ }
if (name != '') { /* ... */ }

// good
if (isValid) { /* ... */ }
if (name !== '') { /* ... */ }
if (collection.length > 0) { /* ... */ }

// no nested ternaries
const thing = foo === 123 ? bar : foobar;
```

### 15. Blocks

- Use braces with all multiline blocks.
- Put `else` on the same line as the `if` block's closing brace.
- If an `if` block always executes a `return`, the subsequent `else` block is unnecessary.

```javascript
// bad
if (test)
  return false;

// good
if (test) return false;

if (test) {
  return false;
}

// if/else
if (test) {
  thing1();
} else {
  thing2();
}
```

### 16. Control Statements

- If a control statement (`if`, `while`, etc.) gets too long, each grouped condition should be on a new line, with the logical operator at the beginning of the line.
- Don't use selection operators in place of control statements.

```javascript
if (
  foo === 123
  && bar === 'abc'
) {
  thing1();
}
```

### 17. Comments

- Use `/** ... */` for multiline comments.
- Use `//` for single-line comments. Place them on a new line above the subject.
- Start all comments with a space for readability.
- Prefix comments with `FIXME:` or `TODO:` to annotate problems or suggest actions.

```javascript
// good single line
// This is a comment
const active = true;

/**
 * Multiline comment explaining the function.
 * @param {string} tag - The tag name.
 * @returns {Element} The created element.
 */
function make(tag) {
  return document.createElement(tag);
}

// TODO: implement caching
// FIXME: should not use global state
```

### 18. Whitespace

- Use soft tabs (spaces) set to 2 spaces.
- Place 1 space before the leading brace.
- Place 1 space before the opening parenthesis in control statements.
- Set off operators with spaces.
- End files with a single newline character.
- Use indentation when making long method chains (more than 2 method chains).
- Leave a blank line after blocks and before the next statement.
- Do not pad blocks with blank lines.
- Do not use multiple blank lines to pad your code.
- Do not add spaces inside parentheses, brackets.
- Add spaces inside curly braces.

```javascript
// bad
function foo(){
  const name='Alice';
}

// good
function foo() {
  const name = 'Alice';
}

// method chaining
$('#items')
  .find('.selected')
  .highlight()
  .end()
  .find('.open')
  .updateCount();
```

### 19. Commas

- Do **not** use leading commas.
- Use trailing commas (dangling commas) for multiline structures.

```javascript
// bad — leading commas
const hero = {
    firstName: 'Ada'
  , lastName: 'Lovelace'
};

// good — trailing commas
const hero = {
  firstName: 'Ada',
  lastName: 'Lovelace',
};

const heroes = [
  'Batman',
  'Superman',
];
```

### 20. Semicolons

- **Always** use semicolons.

```javascript
// bad
const name = 'Alice'

// good
const name = 'Alice';
```

### 21. Type Casting & Coercion

- Perform type coercion at the beginning of the statement.
- Use `String()` for strings, `Number()` for numbers, `Boolean()` or `!!` for booleans.
- Use `parseInt` always with a radix.

```javascript
const val = '4';

// bad
const totalScore = val + 0;

// good
const totalScore = Number(val);
const inputValue = String(someNum);
const hasAge = Boolean(age);
const hasName = !!name;
const count = parseInt(inputValue, 10);
```

### 22. Naming Conventions

- Avoid single-letter names; be descriptive.
- Use **camelCase** for objects, functions, and instances.
- Use **PascalCase** for classes and constructors.
- Use **UPPERCASE_SNAKE_CASE** for constants that are exported and truly immutable.
- Do not use trailing or leading underscores.
- A base filename should exactly match the name of its default export.
- Use **camelCase** when exporting a function; use **PascalCase** when exporting a class / constructor / singleton / function library / bare object.
- Acronyms and initialisms should always be all uppercased or all lowercased.

```javascript
// bad
const OBJEcttsssss = {};
function c() {}
const u = new user();

// good
const thisIsMyObject = {};
function calculateTotal() {}
const user = new User();

// constants
export const API_BASE_URL = 'https://api.example.com';
export const MAX_RETRY_COUNT = 3;

// filename examples
// file: makeStyleGuide.js → export default function makeStyleGuide() {}
// file: User.js              → export default class User {}
```

### 23. Accessors

- Accessor functions for properties are not required.
- Do not use JavaScript getters/setters as they cause unexpected side effects.
- If you do make accessor functions, use `getVal()` and `setVal('value')`.
- If the property/method is a boolean, use `isVal()` or `hasVal()`.

```javascript
// bad
dragon.age();

// good
dragon.getAge();
dragon.setAge(25);
dragon.isAlive();
dragon.hasWings();
```

### 24. Events

- When attaching data payloads to events, pass an object (hash) instead of a raw value.

```javascript
// bad
emitter.emit('itemUpdate', item.id);

// good
emitter.emit('itemUpdate', { itemId: item.id });
```

### 25. Promises & Async/Await

- Prefer `async`/`await` over chaining `.then()` and `.catch()`.
- Always handle errors with `try...catch` in `async` functions.
- Avoid mixing callbacks and promises.
- Use `Promise.all` for concurrent independent async operations.
- Use `Promise.allSettled` when you need results of all promises regardless of rejection.

```javascript
// bad
function fetchData() {
  return getData()
    .then((data) => parseData(data))
    .then((parsed) => validate(parsed))
    .catch((err) => console.error(err));
}

// good
async function fetchData() {
  try {
    const data = await getData();
    const parsed = await parseData(data);
    return validate(parsed);
  } catch (err) {
    console.error(err);
    throw err;
  }
}

// concurrent operations
async function loadDashboard() {
  const [user, posts, notifications] = await Promise.all([
    fetchUser(),
    fetchPosts(),
    fetchNotifications(),
  ]);
  return { user, posts, notifications };
}
```

### 26. Error Handling

- Only throw `Error` objects (or subclasses of `Error`).
- Always catch errors where they can be meaningfully handled.
- Use custom error classes for domain-specific errors.

```javascript
// bad
throw 'Something went wrong';
throw { message: 'error' };

// good
throw new Error('Something went wrong');

class ValidationError extends Error {
  constructor(message, field) {
    super(message);
    this.name = 'ValidationError';
    this.field = field;
  }
}

throw new ValidationError('Invalid email', 'email');
```

### 27. Optional Chaining & Nullish Coalescing

- Use optional chaining (`?.`) to access nested properties that may not exist.
- Use nullish coalescing (`??`) instead of `||` when you want to allow falsy values like `0` or `''`.

```javascript
// bad
const city = user && user.address && user.address.city;
const port = config.port || 3000; // breaks if port is 0

// good
const city = user?.address?.city;
const port = config.port ?? 3000;
```

### 28. Standard Library

- Use `Number.isNaN` instead of global `isNaN`.
- Use `Number.isFinite` instead of global `isFinite`.

```javascript
// bad
isNaN('1.2');
isFinite('2e3');

// good
Number.isNaN('1.2');
Number.isFinite('2e3');
```

---

## Usage

This is a **Prompt-based Skill** (natural language activation).

### How to Use

1. **Automatic Activation**: Simply mention "JavaScript" in your request. The skill will be activated automatically.

2. **Ask for Style Guidance**:
   ```
   "How should I write a JavaScript function that fetches user data?"
   ```

3. **Request Code Review**:
   ```
   "Review this JavaScript code for style issues: [paste code]"
   ```

4. **Generate Compliant Code**:
   ```
   "Write a JavaScript module to handle form validation"
   ```

5. **Ask About Specific Rules**:
   ```
   "What's the correct way to declare variables in JavaScript?"
   "How should I handle async errors in JavaScript?"
   ```

### Examples

**User**: Write a JavaScript utility function to deep clone an object.

**Skill Response**: Generates clean, style-guide-compliant code:

```javascript
/**
 * Deep clones a plain object or array using structured cloning.
 * Falls back to JSON serialization for environments without structuredClone.
 *
 * @param {Object|Array} source - The value to clone.
 * @returns {Object|Array} A deep copy of the source.
 */
function deepClone(source) {
  if (typeof structuredClone === 'function') {
    return structuredClone(source);
  }

  return JSON.parse(JSON.stringify(source));
}

export default deepClone;
```

「開發程式設計」分類下的熱門技能

程式設計大神.Skill開發程式設計

【全棧能力】程式設計大神.Skill:面向複雜真實專案的高階全棧程式設計助手。不止生成程式碼,而是從一句目標接手陌生程式碼庫,拆解需求、補齊實現、追到根因、完成重構、聯調前後端,並把結果推進到能執行、能驗證、能交付。覆蓋 Web、後端、指令碼、iOS、安卓、鴻蒙 ArkUI、微信小程式及其他技術棧,支援中英文工程、疑難 Bug、跨模組任務和長任務續做;用構建、日誌、真實入口、裝置或介面證據說明結果。僅問概念時直接回答,要求落地時持續推進到驗收或明確阻塞。

↓ 1125.9萬★ 82u_42bbb65f
程式設計專家Pro.Skill開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 626.9萬★ 32user_47d655f0
程式設計專家.Skill開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 600.7萬★ 378user_741dc82b
dev-expert開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 528.1萬★ 32user_814dbe54
dev-expert-pro開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 104.7萬★ -user_814dbe54
程式設計專家 Pro開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 98.2萬★ 1user_28275a78
程式設計專家.Skill開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 70.1萬★ 6user_613b33ea
Github開發程式設計

用 gh 命令列工具檢視 GitHub 上的 PR 檢查、工作流執行與 API 查詢的技能。

↓ 48萬★ 714Peter Steinberger

enoyao 的其他技能

資料月份:2026-10 · 下載/星標數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。