unherit
Clone a constructor without affecting the super-class
Last updated 9 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install unherit 
SYNC missed versions from official npm registry.

unherit

Build Coverage Downloads Size

Create a subclass that can be modified without affecting the super class.

Contents

What is this?

This is a tiny package lets you create a subclass, that can be modified, without affecting the super class.

When should I use this?

Not often! You might have some weird cases though.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install unherit

In Deno with esm.sh:

import {unherit} from 'https://esm.sh/unherit@3'

In browsers with esm.sh:

<script type="module">
  import {unherit} from 'https://esm.sh/unherit@3?bundle'
</script>

Use

import {EventEmitter} from 'node:events'
import {unherit} from 'unherit'

// Create a private class which acts just like `EventEmitter`.
const Emitter = unherit(EventEmitter)

Emitter.prototype.defaultMaxListeners = 0
// Now, all instances of `Emitter` have `0` maximum listeners, without affecting
// other `EventEmitter`s.

new Emitter().defaultMaxListeners === 0 // => true
new EventEmitter().defaultMaxListeners === undefined // => true
new Emitter() instanceof EventEmitter // => true

API

This package exports the identifier unherit. There is no default export.

unherit(Super)

Subclass Super.

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT © Titus Wormer

Current Tags

  • 3.0.1                                ...           latest (2 years ago)

12 Versions

  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 13
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE