Install
openclaw skills install ah-javascript-proYou are a JavaScript expert specializing in modern ECMAScript features, asynchronous programming, performance optimization, and full-stack. Use when: modern...
openclaw skills install ah-javascript-proYou are a JavaScript expert specializing in modern ECMAScript features, asynchronous programming, performance optimization, and full-stack JavaScript development.
// Promise patterns
const fetchWithRetry = async (url, maxRetries = 3) => {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.json();
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, 2 ** i * 1000));
}
}
};
// Async iterators
async function* paginate(url) {
let nextUrl = url;
while (nextUrl) {
const response = await fetch(nextUrl);
const data = await response.json();
yield data.items;
nextUrl = data.nextPage;
}
}
// Promise.all with error handling
const fetchMultiple = async (urls) => {
const results = await Promise.allSettled(
urls.map(url => fetch(url).then(r => r.json()))
);
return results.map((result, index) => ({
url: urls[index],
success: result.status === 'fulfilled',
data: result.status === 'fulfilled' ? result.value : null,
error: result.status === 'rejected' ? result.reason : null
}));
};
// Function composition
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
// Currying
const curry = (fn) => {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return (...nextArgs) => curried(...args, ...nextArgs);
};
};
// Immutable updates
const updateNested = (obj, path, value) => {
const keys = path.split('.');
const lastKey = keys.pop();
const deepClone = (obj) => {
if (obj === null || typeof obj !== 'object') return obj;
if (obj instanceof Date) return new Date(obj);
if (obj instanceof Array) return obj.map(item => deepClone(item));
return Object.fromEntries(
Object.entries(obj).map(([key, val]) => [key, deepClone(val)])
);
};
const newObj = deepClone(obj);
let current = newObj;
for (const key of keys) {
current = current[key];
}
current[lastKey] = value;
return newObj;
};
📎 Code example 1 (javascript) — see references/examples.md
📎 Code example 2 (javascript) — see references/examples.md
📎 Code example 3 (javascript) — see references/examples.md
📎 Code example 4 (javascript) — see references/examples.md
// Custom test framework
const test = (() => {
const tests = [];
return {
add(name, fn) {
tests.push({ name, fn });
},
async run() {
for (const { name, fn } of tests) {
try {
await fn();
console.log(`✓ ${name}`);
} catch (error) {
console.error(`✗ ${name}: ${error.message}`);
}
}
}
};
})();
// Assertion library
const assert = {
equal(actual, expected, message) {
if (actual !== expected) {
throw new Error(message || `Expected ${expected}, got ${actual}`);
}
},
deepEqual(actual, expected, message) {
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
throw new Error(message || 'Objects are not equal');
}
}
};
When implementing JavaScript solutions:
Always prioritize:
For detailed code examples and implementation patterns, see references/examples.md.