Descend.js
Descend.js gives you a simple descend
function you can attach to constructors
or call directly to give you an inherited class (constructor with inherited
prototype
) that calls its ancestor constructors automatically when
instantiated.
It also instantiates if any of the descendant constructors are called without
using the new
keyword.
Descend.js also sets the constructor
property correctly on descendants. It
does not set any other property thereby keeping your objects clean.
Installing
Installing on Node.js
npm install descend
Using
Using on constructors
Attach descend
(or name it inherit
or whatever you like) on a constructor:
{ console }Modeldescend = var Child = Model // Will output both "Model initialized." and "Child initialized."
If you want descendant classes to also have the descend
function, you might
want to add it to them afterwards:
var descend = {} Model { var descendant = descend descendantdescend = thisdescend return descendant}
Using as a function
Call descend
with the constructor and the descendant's initializer:
var descend = { console }var Child = // Will output both "Model initialized." and "Child initialized."
License
Descend.js is released under a Lesser GNU Affero General Public License, which in summary means:
- You can use this program for no cost.
- You can use this program for both personal and commercial reasons.
- You do not have to share your own program's code which uses this program.
- You have to share modifications (e.g bug-fixes) you've made to this program.
For more convoluted language, see the LICENSE
file.
About
Andri Möll typed this and the code.
Monday Calendar supported the engineering work.
If you find Descend.js needs improving, please don't hesitate to type to me now at andri@dot.ee or create an issue online.