https://github.com/cahnory/node-inherits
Inheritance module for node.js
https://github.com/cahnory/node-inherits
Last synced: 12 months ago
JSON representation
Inheritance module for node.js
- Host: GitHub
- URL: https://github.com/cahnory/node-inherits
- Owner: cahnory
- License: mit
- Created: 2014-06-21T15:37:37.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-21T15:42:11.000Z (almost 12 years ago)
- Last Synced: 2025-06-10T21:18:06.134Z (about 1 year ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
#node-inherits
Inheritance module for node.js
##Getting started
```
npm install node-inherits
```
##Overview
###Inherits
To inherit from a super constructor, call inherits with your constructor and the super one:
```
Super = function () {};
Constructor = inherits(function () {}, Super);
```
Another way to do this is to call inherits with your super constructor and use its new inherits method:
```
Super = inherits(function () {});
Constructor = Super.inherits(function () {});
```
During inheritance, all constructor are called from the super to last inherited.
```
Super = inherits(function () {
this.name = 'Super';
});
Constructor = Super.inherits(function () {
this.name += ' > Constructor';
});
object = new Constructor();
console.log(object.name); // 'Super > Constructor';
```
###instanceof
Like with node.js util.inherits, your constructor instances will be also instance of super constructor:
```
object = new Constructor();
console.log(object instanceof Constructor); // true
console.log(object instanceof Super); // true
```
###prototype and constructor properties
All properties attached to the constructor and prototype are inherited, taking care of their descriptors.
This means that if Super constructor declared a property with `configurable` set to `false`, it will be preserved.
