Socket
Socket
Sign inDemoInstall

unherit

Package Overview
Dependencies
2
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    unherit

Clone a constructor without affecting the super-class


Version published
Maintainers
1
Install size
18.3 kB
Created

Package description

What is unherit?

The `unherit` npm package is designed to create a factory for customizable classes. It allows you to inherit from a class and then further customize the subclass. This can be particularly useful in scenarios where you want to extend or modify the behavior of existing classes without directly modifying their source code. It's commonly used in the context of creating customizable components or plugins.

What are unherit's main functionalities?

Creating a customizable subclass

This feature allows you to create a subclass from a superclass and then customize that subclass. It's useful for extending existing classes in a modular and reusable way.

const unherit = require('unherit');
const Super = require('./some-super-class');
const Custom = unherit(Super);

// Now, `Custom` can be further extended or modified without affecting `Super`.

Other packages similar to unherit

Readme

Source

unherit

Build Coverage Downloads Size

Create a custom constructor which can be modified without affecting the original class.

Install

npm:

npm install unherit

Use

var EventEmitter = require('events').EventEmitter
var unherit = require('unherit')

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

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

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

API

unherit(Super)

Create a custom constructor which can be modified without affecting the original class.

Parameters
  • Super (Function) — Super-class
Returns

Function — Constructor acting like Super, which can be modified without affecting the original class.

License

MIT © Titus Wormer

Keywords

FAQs

Last updated on 26 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc