node-inherits
Inheritance module for node.js
Last updated 6 years ago by cahnory .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install node-inherits 
SYNC missed versions from official npm registry.

#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.

Current Tags

  • 0.1.0                                ...           latest (6 years ago)

1 Versions

  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |