-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.html
54 lines (39 loc) · 1.33 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<h1>Heritable</h1>
<p>Inheritance mechanisms for making prototypal classes</p>
<h2>Installation</h2>
<p>via [npm]</p>
<pre><code>npm install heritable
</code></pre>
<h2>Usage</h2>
<pre><code>var Heritable = require('heritable.js'),
Animal, Human, // Constructors
animal, human; // instances
Animal = new Heritable('Animal');
animal = new Animal();
console.log('animal instanceof Animal: ' + (animal instanceof Animal));
Human = new Heritable('Human');
human = new Human();
console.log('human instanceof Animal: ' + (human instanceof Animal));
console.log('human instanceof Human: ' + (human instanceof Human));
console.log('animal instanceof Human: ' + (animal instanceof Human));
</code></pre>
<h3>Some details</h3>
<p>You can provide an initializer function and methods for a Heritable class:</p>
<pre><code>animalInitializer = function (o) {
o = o || {};
this.type = o.type;
};
animalMethods = {
getType: function () {
return this.type;
}
};
Animal = new Heritable('Animal', null, animalInitializer, animalMethods);
animal = new Animal({type: 'gorilla'});
console.log('animal type: ' + animal.getType());
</code></pre>
<h2>To Do</h2>
<pre><code>1 do not init if already an object
2 add a method for adding methods to a Heritable class
3 perhaps: distinguish Heritable class methods from members
</code></pre>