
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
inheritance-js
Advanced tools
Simple, lightweight extensions and helpers that make inheritance in JS a breeze, all with pure JavaScript, no extra libraries needed
WARNING: This project has been deprecated and will be removed from NPM and Bower in about 6 months (Feb, 2017)! This project started out as an experiment/learning tool for me, but I ultimately found that the approach taken in the project is VERY inefficient. I'm truly very sorry for any inconvenience this may cause. I recommend as a replacement that you use the native inheritance functionality of JavaScript, it's fast, and really actually not that hard to pick up; or just use ES6 classes. Trying to turn the prototypal inheritance into classical inheritance is really not worth it in JavaScript. It's better to embrace how the language works naturally, once you do, you'll never regret it. I will remove the library from NPM and Bower in about 6 months. If anyone would like to take over the project, just let me know.
Simple, lightweight extensions and helpers that make inheritance in JS a breeze, all with pure JavaScript, no extra libraries needed.
Includes support for AMD, CommonJS, and global inclusion via an HTML script tag.
Special Thanks to YouMightNotNeedjQuery.com. The functions
mix,mixDeep,mixPrototype, andmixPrototypeDeepwere based largly off of their implementation of "Extend" and "Deep Extend".
$ npm install --save inheritance-js$ bower install --save inheritance-js<script src="//npmcdn.com/inheritance-js@0.4.12/dist/inheritance.min.js"></script><script src="//npmcdn.com/inheritance-js@0.4.12"></script>extend).Object (These additions are optional)
Note: If you don't want any native objects to be modified by this library, just use
inheritance.noexts.jsrather thaninheritance.js.
define([ 'inheritance' ], function(I) {
I.mix(...);
var MyObj = I.ObjectDefinition.create(...);P
...
});
var I = require('inheritance');
I.mix(...);
var MyObj = I.ObjectDefinition.create(...);
...
<script type="text/javascript" src="inheritance.min.js" />
<script type="text/javascript">
I.mix(...);
// Notice that `ObjectDefinition` belongs to the `window` object, not the `I` namespace.
var MyObj = ObjectDefinition.create(...);
...
</script>
Creates a new object (I.E. "class") that can be inherited.
NOTE: The new object inherits the native JavaScript
Object.
| Name | Type | Description |
|---|---|---|
objDef | Object | TODO |
Object - The newly created, inheritable, object that inherits Object.Creates a new object (I.E. "class") that CANNOT be inherited.
NOTE: The new object inherits the native JavaScript
Object.
| Name | Type | Description |
|---|---|---|
objDef | Object | TODO |
Object - The newly created, non-inheritable, object that inherits Object.TODO
Creates a new object definition based upon the given objDefProps that inherits the
given parent.
| Name | Type | Description |
|---|---|---|
| parent | Object | The object to be inherited. |
| *objDefProps | Object | An object containing all properties to be used in creating the new object definition that will inherit the given parent object. If this parameter isundefined or null, then a new child object definition is created. TODO: Add reference to the objDefProps spec |
Object - An object created from the given objDefProps that inherits parent.TODO
Makes an object inheritable by adding a function called extend as a "static" property
of the object. (I.E. Calling this function passing MyObject as a parameter, creates
MyObject.extend)
| Name | Type | Description |
|---|---|---|
| obj | Object | The object to make inheritable. |
| *overwrite | Boolean | If true, then an existing extend property will be overwritten regardless of it's value. |
| *ignoreOverwriteError | Boolean | If true, then no error will be thrown if obj.extend already exists and overwrite is not true. |
Object - The modified obj given.TypeError - If obj is undefined or null.TypeError - If obj.extend already exists and overwrite is NOT equal true.TODO
Makes an object sealed by adding a function called extend as a "static" property
of the object that throws an error if it is ever called. Also adds a readonly
"static" property named sealed to the object definition that is set to true,
thus allowing for one to quickly determine whether or not an object's definition
is sealed without catching the error thrown by it's extend function.
(I.E. Calling this function passing MyObject as a parameter, creates
MyObject.extend and MyObject.sealed, where MyObject.sealed will always be
true)
| Name | Type | Description |
|---|---|---|
| obj | Object | The object to seal. |
| *overwrite | Boolean | If true, then an existing extend property will be overwritten regardless of it's value. |
| *ignoreOverwriteError | Boolean | If true, then no error will be thrown if obj.extend already exists and overwrite is not true. |
Object - The modified obj given.TypeError - If obj is undefined or null.TypeError - If obj.extend already exists and overwrite is NOT equal true.TODO
TODO
| Name | Type | Description |
|---|---|---|
| obj | Object | The object to mix into. NOTE: undefined and null are both VALID values for this parameter. If obj is undefined or null, then a new object will be created from the mixins given. |
| mixins | Array | An array of objects whose properties should be mixed into the given obj.NOTE: The order of objects in this array does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The mixed version of obj.TODO
TODO
| Name | Type | Description |
|---|---|---|
| obj | Object | The object to deep mix into. NOTE: undefined and null are both VALID values for this parameter. If obj is undefined or null, then a new object will be created from the mixins given. |
| mixins | Array | An array of objects whose properties should be deep mixed into the given obj.NOTE: The order of objects in this array does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The deep mixed version of obj.TODO
TODO
| Name | Type | Description |
|---|---|---|
| obj | Object | The object containing the prototype to mix into. NOTE: undefined and null are both VALID values for this parameter. If obj is undefined or null, then a new object will be created from the mixins given. |
| mixins | Array | An array of objects whose properties should be mixed into the prototype of the given obj.NOTE: The order of objects in this array does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The mixed version of obj.TypeError - If obj.prototype does not exist.TODO
TODO
| Name | Type | Description |
|---|---|---|
| obj | Object | The object containing the prototype to deep mix into. NOTE: undefined and null are both VALID values for this parameter. If obj is undefined or null, then a new object will be created from the mixins given. |
| mixins | Array | An array of objects whose properties should be deep mixed into the prototype of the given obj.NOTE: The order of objects in this array does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The deep mixed version of obj.TypeError - If obj.prototype does not exist.TODO
ObjectCreates a new object definition based upon the given objDefProps and causes that new object definition to inherit this object.
NOTE: For a list of all native JavaScript objects that have this function added to them, see the wiki page. All of the other native JavaScript objects with this function work exactly as described here (I.E. this piece of documentation is not specific to
Object).
| Name | Type | Description |
|---|---|---|
| objDefProps | Object | An object containing all properties to be used in creating the new object definition that will inherit the Object. If this parameter is undefined or null, then a new child object definition is created. TODO: Add reference to the objDefProps spec |
Object - An object created from the given objDefProps that inherits Object.var ChildObject = Object.extend({
// Child Definition Properties
});
TODO
| Name | Type | Description |
|---|---|---|
| arguments | Object... | Mixin objects whose properties should be mixed into the Object.NOTE: The order of objects passed as arguments does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The Object, mixed with the given mixin objects.var obj = new Object();
obj.value0 = 42;
obj.value1 = "Fish fingers and custard";
obj.value2 = {
value0: 20,
value1: 21
}
obj.func0 = function() {
console.log('func0');
};
obj.func1 = function() {
console.log('func1');
};
var mixin0 = {
mixin0Var0: 0,
mixin0Var1: 0.1,
mixin0Func0: function() {
console.log('mixin0Func0');
},
mixin0Func1: function() {
console.log('mixin0Func1');
},
value2: {
value0: "Blah"
}
};
var mixin1 = {
mixin1Var0: 1,
mixin1Var1: 1.1,
value0: 24,
func0: function() {
console.log('func0 overridden by mixin1');
},
mixin0Func: function() {
console.log('mixin0Func overridden by mixin1');
}
};
var mixin2 = {
mixin2Var: 2,
mixin2Func: function() {
console.log('mixin2Func');
},
value0: 4400,
func0: function() {
console.log('func0 overridden by mixin2');
},
mixin0Var1: 2.1,
mixin0Func0: function() {
console.log('mixin0Func0 overridden by mixin2');
},
mixin1Var0: 2.2
};
// At this point, `obj` can be represented as follows:
// {
// value0: 42,
// value1: "Fish fingers and custard"
// func0: function() {...},
// func1: function() {...}
// }
var newObj = obj.mix(mixin0, mixin1, mixin2);
console.log('newObj.value0 = ' + newObj.value0); // newObj.value0 = 4400
console.log('newObj.value1 = ' + newObj.value1); // newObj.value1 = "Fish fingers and custard"
console.log('newObj.value2.value0 = ' + newObj.value2.value0) // newObj.value2.value0 = "Blah"
console.log('newObj.value2.value1 = ' + newObj.value2.value1) // newObj.value2.value1 = undefined
console.log('newObj.mixin0Var0 = ' + newObj.mixin0Var0); // newObj.mixin0Var0 = 0
console.log('newObj.mixin0Var1 = ' + newObj.mixin0Var1); // newObj.mixin0Var1 = 2.1
console.log('newObj.mixin1Var0 = ' + newObj.mixin1Var0); // newObj.mixin1Var0 = 1
console.log('newObj.mixin1Var1 = ' + newObj.mixin1Var1); // newObj.mixin1Var1 = 2.1
console.log('newObj.mixin2Var = ' + newObj.mixin2Var); // newObj.mixin2Var = 2
newObj.func0() // Prints "func0 overridden by mixin2"
newObj.func1() // Prints "func1"
newObj.mixin0Func0() // Prints "mixin0Func0 overridden by mixin2"
newObj.mixin0Func1() // Prints "mixin0Func1 overridden by mixin1"
newObj.mixin2Func() // Prints "mixin2Func"
TODO
| Name | Type | Description |
|---|---|---|
| arguments | Object... | Mixin objects whose properties should be deep mixed into the Object.NOTE: The order of objects in this array does matter! If there are properties present in multiple mixin objects, then the mixin with the largest index value overwrite any values set by the lower index valued mixin objects. |
Object - The Object, deep mixed with the given mixin objects.TODO
See contribution documentation page for details.
FAQs
Simple, lightweight extensions and helpers that make inheritance in JS a breeze, all with pure JavaScript, no extra libraries needed
We found that inheritance-js 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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.