install
source · Clone the upstream repo
git clone https://github.com/Intense-Visions/harness-engineering
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/codex/js-prototype-pattern" ~/.claude/skills/intense-visions-harness-engineering-js-prototype-pattern-a31937 && rm -rf "$T"
manifest:
agents/skills/codex/js-prototype-pattern/SKILL.mdsource content
JS Prototype Pattern
Share properties and methods across instances via the prototype chain
When to Use
- You have many instances that should share methods without duplicating them in memory
- You need to extend built-in types or add methods to third-party objects
- You want lightweight objects where method storage is shared, not per-instance
Instructions
- Define shared methods on the constructor's
object — not inside the constructor function..prototype - Instance data (unique per instance) goes on
inside the constructor.this - Use
for explicit prototype assignment without a constructor.Object.create(proto) - Avoid modifying built-in prototypes (Array, String, Object) — it causes library conflicts.
function Dog(name) { this.name = name; } Dog.prototype.bark = function () { return `${this.name} says woof!`; }; const d1 = new Dog('Rex'); const d2 = new Dog('Spot'); // Both share the same bark function in memory console.log(d1.bark === d2.bark); // true
- Prefer ES6
syntax — it uses the prototype chain under the hood but is more readable.class - Use
orhasOwnProperty()
to distinguish own vs inherited properties.Object.hasOwn()
Details
Every JavaScript object has an internal
[[Prototype]] link. When you access a property, the engine walks the chain: own properties first, then the prototype, then the prototype's prototype, until null. This is the prototype chain.
Trade-offs:
- Shared mutable properties on the prototype are dangerous — if one instance mutates a shared array/object, all instances see the change
- The prototype chain adds one lookup level per tier — negligible for most code, but avoid very deep chains
syntax is clearer than manualclass
manipulation.prototype
When NOT to use:
- When instances need truly private state — use closures or ES2022 private class fields (
) instead#field - When you need multiple inheritance — JS has single prototype chain; use mixins instead
Source
https://patterns.dev/javascript/prototype-pattern
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.