npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

isotropic-prototype-chain

v0.13.1

Published

A generator that walks the prototype chain of an object

Readme

isotropic-prototype-chain

npm version License

A generator function that walks through the prototype chain of an object.

Why Use This?

  • Simple Iteration: Easily iterate through all prototypes in an object's chain
  • Generator-Based: Uses JavaScript generators for efficient lazy iteration
  • Reflection API: Built on the modern Reflect API for reliable prototype access
  • No Dependencies: Lightweight implementation with zero runtime dependencies

Installation

npm install isotropic-prototype-chain

Usage

import _prototypeChain from 'isotropic-prototype-chain';

// Create an object with a prototype chain
class Animal {}
class Mammal extends Animal {}
class Dog extends Mammal {}

const dog = new Dog();

// Iterate through the prototype chain
for (const prototype of prototypeChain(dog)) {
    console.log(prototype);
}
// Outputs: Dog instance, Mammal.prototype, Animal.prototype, Object.prototype, null

API

prototypeChain(object)

A generator function that yields each prototype in the chain, starting with the object itself and continuing up to Object.prototype.

Parameters

  • object (Object): The object whose prototype chain to iterate.

Returns

  • (Generator): A generator that yields each object in the prototype chain, starting with the input object and continuing to the end of the chain.

Examples

Basic Usage

import _prototypeChain from 'isotropic-prototype-chain';

const object = {
        a: 1
    },
    prototypeChain = [
        ..._prototypeChain(object)
    ];

console.log(prototypeChain); // [{ a: 1 }, Object.prototype]

Custom Object Inheritance

import _prototypeChain from 'isotropic-prototype-chain';

// Create a chain of objects with custom inheritance
const _child = {
        name: 'Child',
    },
    _grandparent = {
        name: 'Grandparent'
    },
    _parent = {
        name: 'Parent'
    };

Object.setPrototypeOf(_child, _parent);
Object.setPrototypeOf(_parent, _grandparent);

// Print the chain of names
for (const object of _prototypeChain(_child)) {
    console.log(object.name);
}
// Outputs: "Child", "Parent", "Grandparent", undefined

Collecting All Properties in the Prototype Chain

import _prototypeChain from 'isotropic-prototype-chain';

// Get all property names from the entire prototype chain
const _getPropertyNameSet = object => {
    const propertyNameSet = new Set();

    for (const prototype of _prototypeChain(object)) {
        for (const propertyName of Object.getOwnPropertyNames(prototype)) {
            propertyNameSet.add(propertyName);
        }
    }

    return propertyNameSet;
}

class A {
    constructor () {
        this.propA = 'A';
    }

    methodA () {}
}

class B extends A {
    constructor () {
        super();

        this.propB = 'B';
    }

    methodB () {}
}

class C extends B {
    constructor () {
        super();

        this.propC = 'C';
    }

    methodC() {}
}

console.log(...getPropertyNameSet(new C()));
// Outputs: propA propB propC constructor methodC methodB methodA, etc.

Checking Multiple Inheritance or Mixins

import _prototypeChain from 'isotropic-prototype-chain';

// Check if an object inherits from multiple specific constructors/classes
const _inheritsFrom = (object, ...constructorFunctions) => {
    const prototypeSet = new Set();

    // Collect all constructor prototypes to check against
    constructorFunctions.forEach(constructorFunction => {
        prototypeSet.add(constructorFunction.prototype);
    });

    // Check if any prototype in the chain matches any of the constructor prototypes
    let foundCount = 0;

    for (const prototype of _prototypeChain(object)) {
        if (prototypeSet.has(prototype)) {
            foundCount += 1;
        }
    }

    return foundCount === constructorFunctions.length;
}

// Test with inheritance
class Base {}
class Derived extends Base {}

{
    const object = new Derived();

    console.log(_inheritsFrom(object, Derived, Base)); // true
    console.log(_inheritsFrom(object, Base));          // true
    console.log(_inheritsFrom(object, Array));         // false
}

Contributing

Please refer to CONTRIBUTING.md for contribution guidelines.

Issues

If you encounter any issues, please file them at https://github.com/ibi-group/isotropic-prototype-chain/issues