用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-javascript --skill patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | patterns |
| description | JavaScript design patterns and architectural best practices. |
| sasmp_version | 1.3.0 |
| bonded_agent | 06-modern-es6-advanced |
| bond_type | PRIMARY_BOND |
| skill_type | reference |
| response_format | code_first |
| max_tokens | 1500 |
| parameter_validation | {"required":["topic"],"optional":["pattern_type"]} |
| retry_logic | {"on_ambiguity":"ask_clarification","fallback":"show_common_patterns"} |
| observability | {"entry_log":"Patterns skill activated","exit_log":"Patterns reference provided"} |
Factory
function createUser(type) {
const users = {
admin: () => ({ role: 'admin', permissions: ['all'] }),
user: () => ({ role: 'user', permissions: ['read'] })
};
return users[type]?.() ?? users.user();
}
Singleton
class Database {
static #instance;
static getInstance() {
if (!Database.#instance) {
Database.#instance = new Database();
}
return Database.#instance;
}
}
Builder
class QueryBuilder {
#query = { select: '*', from: '', where: [] };
select(fields) { this.#query.select = fields; return this; }
from() { .#query. = table; ; }
() { .#query..(condition); ; }
() { .#query; }
}
()
.()
.()
.()
.();
Module
const Counter = (function() {
let count = 0; // Private
return {
increment: () => ++count,
decrement: () => --count,
get: () => count
};
})();
Facade
class ApiClient {
async getUser(id) {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) throw new Error('Failed');
return response.json();
}
async updateUser(id, data) {
return this.#request('PUT', `/api/users/${id}`, data);
}
#request(method, url, data) {
return fetch(url, {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(r => r.json());
}
}
Decorator
function withLogging(fn) {
return function(...args) {
console.log('Calling:', fn.name, args);
const result = fn.apply(this, args);
console.log('Result:', result);
return result;
};
}
const add = withLogging((a, b) => a + b);
Observer (Pub/Sub)
class EventEmitter {
#events = new Map();
on(event, handler) {
if (!this.#events.has(event)) this.#events.set(event, []);
this.#events.get(event).push(handler);
return () => this.off(event, handler);
}
off(event, handler) {
const handlers = this.#events.get(event) ?? [];
this.#events.set(event, handlers.filter(h => h !== handler));
}
emit(event, data) {
(this.#events.get(event) ?? []).forEach(h => h(data));
}
}
Strategy
const validators = {
email: (v) => /\S+@\S+/.test(v),
phone: (v) => /^\d{10}$/.test(v),
required: (v) => v?.trim().length > 0
};
function validate(value, rules) {
return rules.every(rule => validators[rule]?.(value) ?? true);
}
validate('test@test.com', ['required', 'email']); // true
Command
class CommandManager {
#history = [];
#index = -1;
execute(command) {
command.execute();
this.#history = this.#history.slice(0, this.#index + 1);
this.#history.push(command);
this.#index++;
}
undo() {
if (this.#index >= 0) {
this.#history[this.#index--].undo();
}
}
redo() {
if (this.#index < this.#history.length - 1) {
this.#history[++this.#index].execute();
}
}
}
Composition
const withLogger = (obj) => ({
...obj,
log: (msg) => console.log(`[${obj.name}] ${msg}`)
});
const withValidator = (obj) => ({
...obj,
validate: () => !!obj.value
});
const field = withValidator(withLogger({ name: 'email', value: '' }));
Middleware
function createPipeline(...middlewares) {
return (input) => middlewares.reduce(
(acc, fn) => fn(acc),
input
);
}
const process = createPipeline(
(x) => x.trim(),
(x) => x.toLowerCase(),
(x) => x.replace(/\s+/g, '-')
);
process(' Hello World '); // 'hello-world'
| Pattern | Use When |
|---|---|
| Factory | Multiple similar objects |
| Singleton | Single shared instance |
| Observer | Event-driven communication |
| Strategy | Swappable algorithms |
| Facade | Complex subsystem |