Skip to main content
skill CX Codex

prototype-pattern — Claude Code skill: what it does, how to install

Teaches coding assistants the JavaScript Prototype Pattern. It shows how to share methods via the prototype chain to keep memory consumption low.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PatternsDev/skills --skill prototype-pattern -a claude-code
Open on GitHub

What prototype-pattern does

This skill guides the agent on prototype-based inheritance within **/*.js and **/*.ts files. It instructs the assistant to place shared methods on prototypes rather than recreating identical functions across individual instances.

Two concrete implementation paths are detailed. The first uses standard ES6 classes, which automatically attach methods to the constructor prototype. The second relies on Object.create() for explicit prototype binding. The rules also cover prototype chain navigation using extends and super.

The skill strictly targets JavaScript and TypeScript file extensions. If your codebase does not instantiate multiple objects of the same shape, this pattern will offer no practical advantage.

What it helps with

  • prevent function duplication across repetitive object instances
  • set up explicit prototype delegation with Object.create()
  • implement class-based prototype inheritance using extends and super
  • reduce runtime memory overhead by sharing common methods

Example prompts for the agent

  • Refactor this Dog class to put common methods on the prototype chain
  • Create an object inheriting from pet using Object.create instead of a class
  • Review user-factory.ts to ensure methods are shared rather than copied per instance

How to install prototype-pattern

1Skills CLI (Vercel)

npx skills add PatternsDev/skills --skill prototype-pattern -a claude-code

2Manually: put the files in place

~/.claude/skills/prototype-pattern/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/prototype-pattern/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about prototype-pattern

How to install prototype-pattern in Claude Code?

Run npx skills add PatternsDev/skills --skill prototype-pattern -a claude-code. The file will be written to ~/.claude/skills/prototype-pattern/SKILL.md.

What does prototype-pattern do?

It guides coding agents to share properties and methods through the native JavaScript prototype chain, reducing memory usage across multiple objects.

Which file patterns trigger this skill?

The skill configuration scopes its rules to match **/*.js and **/*.ts files.

Source text

SKILL.md · MIT
---
name: prototype-pattern
description: Teaches the prototype pattern for property sharing via the prototype chain. Use when creating many objects of the same type that should share methods or properties efficiently.
paths:
  - "**/*.js"
  - "**/*.ts"
license: MIT
metadata:
  author: patterns.dev
  version: "1.1"
related_skills:
  - "module-pattern"
  - "singleton-pattern"
---

# Prototype Pattern

The prototype pattern is a useful way to share properties among many objects of the same type. The prototype is an object that's native to JavaScript, and can be accessed by objects through the prototype chain.

In our applications, we often have to create many objects of the same type. A useful way of doing this is by creating multiple instances of an ES6 class.

## When to Use

- Use this when many objects need access to the same methods without duplicating them
- This is helpful for understanding JavaScript's inheritance model and ES6 classes

## Instructions

- Use ES6 classes to automatically add methods to the prototype
- Use `Object.create()` to create objects with a specific prototype
- Leverage the prototype chain for inheritance (`extends` keyword in ES6 classes)
- Understand that properties on the prototype are shared and not duplicated per instance

## Details

Let's say we want to create many dogs! In our example, dogs can't do that much: they simply have a name, and they can bark!

```js
class Dog {
  constructor(name) {
    this.name = name;
  }

  bark() {
    return `Woof!`;
  }
}

const dog1 = new Dog("Daisy");
const dog2 = new Dog("Max");
const dog3 = new Dog("Spot");
```

Notice here how the `constructor` contains a `name` property, and the class itself contains a `bark` property. When using ES6 classes, all properties that are defined on the class itself, `bark` in this case, are automatically added to the `prototype`.

We can see the `prototype` directly through accessing the `prototype` property on a constructor, or through the `__proto__` property on any _instance_.

```js
console.log(Dog.prototype);
// constructor: ƒ Dog(name, breed) bark: ƒ bark()

console.log(dog1.__proto__);
// constructor: ƒ Dog(name, breed) bark: ƒ bark()
```

The value of `__proto__` on any instance of the constructor, is a direct reference to the constructor's prototype! Whenever we try to access a property on an object that doesn't exist on the object directly, JavaScript will _go down the prototype chain_ to see if the property is available within the prototype chain.

The prototype pattern is very powerful when working with objects that should have access to the same properties. Instead of creating a duplicate of the property each time, we can simply add the property to the prototype, since all instances have access to the prototype object.

Since all instances have access to the prototype, it's easy to add properties to the prototype even after creating the instances.

Say that our dogs shouldn't only be able to bark, but they should also be able to play! We can make this possible by adding a `play` property to the prototype.

The term **prototype chain** indicates that there could be more than one step. Indeed! So far, we've only seen how we can access properties that are directly available on the first object that `__proto__` has a reference to. However, prototypes themselves also have a `__proto__` object!

Let's create another type of dog, a super dog! This dog should inherit everything from a normal `Dog`, but it should also be able to fly. We can create a super dog by extending the `Dog` class and adding a `fly` method.

```js
class SuperDog extends Dog {
  constructor(name) {
    super(name);
  }

  fly() {
    return "Flying!";
  }
}
```

We have access to the `bark` method, as we extended the `Dog` class. The value of `__proto__` on the prototype of `SuperDog` points to the `Dog.prototype` object!

It gets clear why it's called a prototype _chain_: when we try to access a property that's not directly available on the object, JavaScript recursively walks down all the objects that `__proto__` points to, until it finds the property!

### `Object.create`

The `Object.create` method lets us create a new object, to which we can explicitly pass the value of its prototype.

```js
const dog = {
  bark() {
    return `Woof!`;
  },
};

const pet1 = Object.create(dog);
```

Although `pet1` itself doesn't have any properties, it does have access to properties on its prototype chain! Since we passed the `dog` object as `pet1`'s prototype, we can access the `bark` property.

`Object.create` is a simple way to let objects directly inherit properties from other objects, by specifying the newly created object's prototype. The new object can access the new properties by walking down the prototype chain.


The prototype pattern allows us to easily let objects access and inherit properties from other objects. Since the prototype chain allows us to access properties that aren't directly defined on the object itself, we can avoid duplication of methods and properties, thus reducing the amount of memory used.

## Source

- [patterns.dev/vanilla/prototype-pattern](https://patterns.dev/vanilla/prototype-pattern)

### References

- [Object.create - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
- [Prototype - ECMA](https://www.ecma-international.org/ecma-262/5.1/#sec-4.3.5)

© patterns.dev · MIT · PatternsDev/skills

Similar skills

All skills for Programming languages →

From the same set46

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor