Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inherits

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inherits

A tiny simple way to do classic inheritance in js

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is inherits?

The inherits npm package is a simple utility module that allows you to implement inheritance in JavaScript. It facilitates the prototype chain linkage between a constructor function (child) and another constructor function (parent) to achieve classical inheritance patterns.

What are inherits's main functionalities?

Inheritance

This code demonstrates how to use the inherits package to set up classical inheritance between a custom constructor MyStream and the built-in EventEmitter constructor. It allows instances of MyStream to inherit methods and properties from EventEmitter.

var inherits = require('inherits');
var EventEmitter = require('events').EventEmitter;

function MyStream() {
  EventEmitter.call(this);
}

inherits(MyStream, EventEmitter);

MyStream.prototype.write = function(data) {
  this.emit('data', data);
};

var stream = new MyStream();
console.log(stream instanceof EventEmitter); // true
console.log(MyStream.super_ === EventEmitter); // true

Other packages similar to inherits

Keywords

FAQs

Package last updated on 27 Aug 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc