-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsclass.html
54 lines (46 loc) · 1.52 KB
/
jsclass.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>jsclass</title>
<script type="text/javascript" charset="utf-8" src="http://documentcloud.github.com/underscore/underscore.js">
</script>
<script type="text/javascript" charset="utf-8" src="vendor/underscore/underscore.js"></script>
<script type="text/javascript" charset="utf-8" src="lib/klass.js"></script>
<script type="text/javascript" charset="utf-8">
/*
Inheritence systems:
http://ejohn.org/blog/simple-javascript-inheritance/
* uses init method
* has class.extend
http://mootools.net/docs/core/Class/Class
* uses Extends... weird
http://www.danwebb.net/2008/1/31/low-pro-for-jquery
http://api.prototypejs.org/language/Class/
My implementation:
* should be simple
* should follow js convention but simplify the annoying parts
* ie method passed in should be the constructor
* should prevent accidental calling of the constructor with out the new keyword
* should _not_ attempt to reimplement a classical OOP system perse
* should make it simple to add methods and to reference the parent's methods
*/
var Animal = K(function() {
this.noise = 'poof';
});
var Dog = K(function() {
this.noise = 'woof';
})
.proto(Animal)
.mixin({
bark: function() {
console.log(this.noise);
}
});
var d = new Dog;
d.bark();
</script>
</head>
</html>
<body id="jsclass" onload="">
</body>