Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Node.JS 'inherits' replacement that supports mixins.
Call it like the normal Node.JS 'inherits' and optionally supply additional arguments to add as mixins. All prototype methods of mixin constructors are added to the prototype of the class.
If inheritz is called on a constructor that already inherits from something (ie, it already has prototype methods), then all parameters are added as mixins. This makes it useful for adding mixins to ES6 classes.
var inherits = require('inheritz');
function SuperClassA() {}
SuperClassA.prototype.methodA = function() {
return 'A';
};
function SuperClassB() {}
SuperClassB.prototype.methodB = function() {
return 'B';
};
function SuperClassC() {}
SuperClassC.prototype.methodC = function() {
return 'C';
};
function MyClass() {
SuperClassA.call(this);
SuperClassB.call(this);
SuperClassC.call(this);
}
inherits(MyClass, SuperClassA, SuperClassB, SuperClassC);
var myClass = new MyClass();
myClass.methodA();
myClass.methodB();
myClass.methodC();
By default, if a method on a mixin conflicts with an existing method already belonging to the prototype, the mixin will yield to the existing method.
var inherits = require('inheritz');
function SuperClassA() {}
SuperClassA.prototype.method = function() {
return 'A';
};
function SuperClassB() {}
SuperClassB.prototype.method = function() {
return 'B';
};
function MyClass() {
SuperClassA.call(this);
SuperClassB.call(this);
}
inherits(MyClass, SuperClassA);
inherits(MyClass, SuperClassB);
var myClass = new MyClass();
console.log(myClass.method()); // prints 'A'
However, if you supply a boolean true
as the first parameter to inheritz, this behavior
is reversed:
var inherits = require('inheritz');
function SuperClassA() {}
SuperClassA.prototype.method = function() {
return 'A';
};
function SuperClassB() {}
SuperClassB.prototype.method = function() {
return 'B';
};
function MyClass() {
SuperClassA.call(this);
SuperClassB.call(this);
}
inherits(MyClass, SuperClassA);
inherits(true, MyClass, SuperClassB);
var myClass = new MyClass();
console.log(myClass.method()); // prints 'B'
FAQs
Node.JS inherits replacement with support for mixins
The npm package inheritz receives a total of 3 weekly downloads. As such, inheritz popularity was classified as not popular.
We found that inheritz demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.