From harness-claude
Implements JS Constructor Pattern using ES6 classes for object instances with validation, private fields, shared methods, and instanceof checks. Use when creating multiple similar objects with init logic.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Use constructor functions or ES6 classes to create and initialize objects
Shares properties and methods across JavaScript instances via prototype chain. Use for memory-efficient objects with many shared methods, avoiding per-instance duplication.
Teaches ES6+ features like arrow functions, destructuring, async/await, promises, and functional patterns for refactoring legacy JavaScript and optimizing web apps.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
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