-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
100 lines (80 loc) · 2.4 KB
/
README.txt
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
===== ClassClass =====
** CAUTION: This is still a work in progress **
Copyright (c) 2011 Ken Colton
Heavily inspired by John Resig's Simple Inheritance.
http://ejohn.org/blog/simple-javascript-inheritance/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
License available in GPL-LICENSE.txt or <http://www.gnu.org/licenses/>.
===== Description =====
ClassClass allows you to create JavaScript "Classes" (prototype objects) using a familiar Class syntax.
===== Usage =====
See demo.html for complete usage.
/**
* We define a number of classes in a heirarchy and then demo
* imporant OO features such as calling the parent function,
* method overriding and lookup
*/
/**
* Define the Animal class
*/
new Class('Animal').With({
__construct: function(name)
{
this.name = name;
console.log('constructing animal ' + this.name);
},
foo: function()
{
console.log('foo animal ' + this.name);
// This will go all the way back down to the base bar for the object
this.bar();
}
});
/**
* Define the K9 class
*/
new Class('K9').Extends('Animal').With({
__construct: function(name)
{
console.log('constructing k9 ' + name);
// Calling parents also works for constructors
this.parentFunc(name);
},
foo: function()
{
console.log('foo k9 ' + this.name);
// Call parnet foo
this.parentFunc();
},
bar: function()
{
console.log('bar k9 ' + this.name);
}
});
/**
* Define the Animal class
*/
new Class('Dog').Extends('K9').With({
// Note there is no constructor here and K9 constructor will automatically get called
foo: function()
{
console.log('foo dog ' + this.name);
// Call the parent foo
this.parentFunc();
},
bar: function()
{
console.log('bar dog ' + this.name);
// Call the parent bar
this.parentFunc();
}
});
var wonton = new Dog('wonton');
wonton.foo();