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 🙏

© 2026 – Pkg Stats / Ryan Hefner

extends-classes

v2.0.0

Published

Extend from multiple ES6 classes.

Readme

Extends Classes

CI npm

Extend from multiple classes in JavaScript.

Installation

$ npm install extends-classes

Usage

const classes = require('extends-classes');

class Swimmer {
  swim() {
    return `${this.name} swims`;
  }
}

class Flyer {
  constructor(name) {
    this.name = name;
  }
  fly() {
    return `${this.name} flies`;
  }
}

class Duck extends classes(Swimmer, Flyer) {
  quack() {
    return `${this.name} quacks`;
  }
}

const duck = new Duck('Donald');

duck.swim(); // Donald swims
duck.fly(); // Donald flies
duck.quack(); // Donald quacks

How it works

classes(A, B, C) returns a new class to extend. That class takes on, from each class you pass:

  • Methods, getters and setters, including those the class inherited from its own parent.
  • Static methods and properties.
  • Instance properties. When you create an instance, each class is constructed once with the arguments passed to super(...), and the properties its constructor sets are copied onto your instance.

When two classes define the same name, the later class in the list wins. Anything defined on your own class overrides them all, and can reach the mixed in version with super.method().

Things to know:

  • instance instanceof A is false. The members of A are copied; A is not in the prototype chain.
  • Each constructor runs against its own temporary object, not your instance, so a constructor that calls a method only another class provides will not find it.
  • Private fields (#field) belong to the temporary object and are not copied.

Missing methods

method-missing is included in the stack. Define __call to catch calls to methods that do not exist:

class Test extends classes(A, B, C) {

  __call(method, args) {
    return `'${method}()' is missing!`;
  }

}

new Test().somethingThatIsNonExistent();
// 'somethingThatIsNonExistent()' is missing!

Without __call, a missing property is undefined as on any object.

Upgrading from 1.x

  • Instance properties now live on each instance. In 1.x they were written to the shared prototype, so one instance's state showed up on every other.
  • Getters and setters are copied as accessors. In 1.x a getter was read once, against the prototype, and its result copied.
  • Inherited methods and static members are now included.
  • Instances can be passed to JSON.stringify, awaited and returned from async functions. In 1.x these threw unless the class defined __call.
  • Reading a missing property on a class without __call returns undefined instead of throwing MethodMissingError.

Tests

$ npm install
$ npm test

License

MIT