From harness-claude
Implements JavaScript Decorator pattern to dynamically extend functions and objects with behaviors like logging, caching, auth without source modification. Use for composing cross-cutting concerns at runtime.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Extend object behavior dynamically without modifying its source
Implements GOF Decorator pattern in TypeScript: class-based for objects (encryption, compression) and function-based for async functions (retry). Use to add stackable runtime behaviors without subclassing.
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.
Teaches ES6+ features like arrow functions, destructuring, async/await, promises, and functional patterns for refactoring legacy JavaScript and optimizing web apps.
Share bugs, ideas, or general feedback.
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