modern-javascript-patterns
БесплатноБез исполняемых скриптовНе проверенMaster ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional…
Об этом скилле
Modern JavaScript Patterns
Master ES6+ features and functional programming for clean, efficient code.
Arrow Functions
// Basic syntax
const add = (a, b) => a + b;
const double = x => x * 2;
const getRandom = () => Math.random();
// Multi-line (need braces)
const processUser = user => {
const normalized = user.name.toLowerCase();
return { ...user, name: normalized };
};
// Returning objects (wrap in parentheses)
const createUser = (name, age) => ({ name, age });
// Lexical 'this' binding
class Counter {
increment = () => { this.count++; }; // 'this' preserved
}
Destructuring
// Object destructuring
const { name, email } = user;
const { name: userName } = user; // Rename
const { age = 25 } = user; // Default value
const { address: { city } } = user; // Nested
const { id, ...userData } = user; // Rest
// Array destructuring
const [first, second] = numbers;
const [, , third] = numbers; // Skip elements
const [head, ...tail] = numbers; // Rest
let [a, b] = [1, 2]; [a, b] = [b, a]; // Swap
// Function parameters
function greet({ name, age = 18 }) {
console.log(`Hello ${name}`);
}
Spread & Rest
// Spread arrays
const combined = [...arr1, ...arr2];
const copy = [...arr1];
// Spread objects
const settings = { ...defaults, ...userPrefs };
const newObj = { ...user, age: 31 };
// Rest parameters
function sum(...numbers) {
return numbers.reduce((total, n) => total + n, 0);
}
Async/Await
// Basic usage
async function fetchUser(id) {
try {
const response = await fetch(`/api/users/${id}`);
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}
// Parallel execution
const [user1, user2] = await Promise.all([
fetchUser(1),
fetchUser(2)
]);
// Promise combinators
Promise.all(promises); // Wait for all
Promise.allSettled(promises); // All results, regardless of outcome
Promise.race(promises); // First to complete
Promise.any(promises); // First to succeed
Functional Patterns
Array Methods
const users = [{ id: 1, name: 'John', active: true }, ...];
// Map - Transform
const names = users.map(u => u.name);
// Filter - Select
const activeUsers = users.filter(u => u.active);
// Reduce - Aggregate
const totalAge = users.reduce((sum, u) => sum + u.age, 0);
// Chaining
const result = users
.filter(u => u.active)
.map(u => u.name)
.sort()
.join(', ');
// Other useful methods
users.find(u => u.id === 2); // First match
users.findIndex(u => u.name === 'Jane'); // Index of first match
users.some(u => u.active); // At least one matches
users.every(u => u.age >= 18); // All match
userTags.flatMap(u => u.tags); // Map and flatten
Higher-Order Functions
// Currying
const multiply = a => b => a * b;
const double = multiply(2);
// Memoization
function memoize(fn) {
const cache = new Map();
return (...args) => {
const key = JSON.stringify(args);
if (!cache.has(key)) cache.set(key, fn(...args));
return cache.get(key);
};
}
// Composition
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
Immutability
// Arrays
const withNew = [...arr, newItem]; // Add
const without = arr.filter(x => x !== item); // Remove
const updated = arr.map(x => x.id === id ? { ...x, name } : x);
// Objects
const updated = { ...user, age: 31 }; // Update
const { password, ...safe } = user; // Remove key
Modern Operators
// Optional chaining
const city = user?.address?.city;
const result = obj.method?.();
const first = arr?.[0];
// Nullish coalescing
const value = null ?? 'default'; // 'default'
const value = 0 ?? 'default'; // 0 (not 'default')
// Logical assignment
a ??= 'default'; // a = a ?? 'default'
a ||= 'default'; // a = a || 'default'
a &&= value; // a = a && value
Modules
// Named exports
export const PI = 3.14159;
export function add(a, b) { return a + b; }
// Default export
export default function multiply(a, b) { return a * b; }
// Importing
import multiply, { PI, add } from './math.js';
import * as Math from './math.js';
// Dynamic import
const module = await import('./feature.js');
Performance Patterns
// Debounce
function debounce(fn, delay) {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
}
// Throttle
function throttle(fn, limit) {
let inThrottle;
return (...args) => {
if (!inThrottle) {
fn(...args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
Best Practices
- Use const by default - Only le
Установить modern-javascript-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл modern-javascript-patterns?
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.
Как установить скилл modern-javascript-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modern-javascript-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic