From harness-claude
Implements the Decorator pattern in JavaScript to dynamically extend object/function behavior without modifying source. Useful for composing cross-cutting concerns like logging, caching, or auth checks.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:js-decorator-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Extend object behavior dynamically without modifying its source
Extend object behavior dynamically without modifying its source
@decorator.const enhanced = decorate(original).// Functional decorator — adds logging
function withLogging(fn) {
return function (...args) {
console.log(`Calling ${fn.name} with`, args);
const result = fn.apply(this, args);
console.log(`${fn.name} returned`, result);
return result;
};
}
function add(a, b) {
return a + b;
}
const loggedAdd = withLogging(add);
loggedAdd(2, 3); // logs call and return
const fn = withAuth(withLogging(handler)).name and length with Object.defineProperty if needed.The Decorator pattern adds behavior to individual objects without affecting other objects of the same class. In JavaScript, this is most naturally expressed as higher-order functions — functions that take a function and return a new function with added behavior.
Trade-offs:
.name and .length unless explicitly preservedwithAuth(withLogging(fn)) logs before auth checksWhen NOT to use:
https://patterns.dev/javascript/decorator-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeAttaches additional behaviors to objects at runtime by wrapping them in decorator objects. Useful for stacking cross-cutting concerns like logging, caching, validation, or retry without subclassing.
Adds runtime object responsibilities via wrapping (Decorator pattern). Applies to OOP codebases, especially Java I/O streams, Python decorators, and Django middleware.
Generates Decorator pattern for PHP 8.4: interface, abstract decorator, concrete decorators (logging, caching, metrics, transactional), optional factory, and unit tests. For dynamic behavior without inheritance.