From harness-claude
Guides using ES6 classes and constructor functions for object creation in JavaScript, including private fields, memoization, and prototype-based inheritance.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:js-constructor-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Use constructor functions or ES6 classes to create and initialize objects
Use constructor functions or ES6 classes to create and initialize objects
instanceof for type checkingclass syntax over function constructors for readability.this.x = ...).#field) for data that should not be accessible externally.class Rectangle {
#area = null;
constructor(width, height) {
if (width <= 0 || height <= 0) throw new RangeError('Dimensions must be positive');
this.width = width;
this.height = height;
}
getArea() {
if (this.#area === null) {
this.#area = this.width * this.height; // memoize
}
return this.#area;
}
toString() {
return `Rectangle(${this.width}x${this.height})`;
}
}
const r = new Rectangle(4, 5);
console.log(r.getArea()); // 20
console.log(r instanceof Rectangle); // true
The Constructor pattern is the foundation of object-oriented JavaScript. ES6 classes are syntactic sugar over prototype-based inheritance — class bodies define methods on ClassName.prototype, exactly like the older function Constructor() {} approach.
Trade-offs:
this — prefer immutable value objects for datathis binding issues arise when class methods are passed as callbacks — use arrow functions or .bind()#field) are not accessible in subclasses without gettersWhen NOT to use:
https://patterns.dev/javascript/constructor-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeExplains the JavaScript prototype pattern for sharing methods across instances via the prototype chain. Includes trade-offs, ES6 class syntax, and antipatterns.
Provides instructions for implementing the Prototype design pattern (cloning objects) in Python, JavaScript, and Java. Useful when object creation is expensive or runtime type is unknown.
Teaches ES6+ features like arrow functions, destructuring, async/await, promises, and functional patterns for refactoring legacy JavaScript and optimizing web apps.