forked from LinkedInAttic/Fiber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.html
141 lines (117 loc) · 2.76 KB
/
examples.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<script src="src/fiber.js"></script>
</head>
<body>
<script>
var SuperClass = Fiber.extend(function(base) {
return {};
});
var s = new SuperClass();
// Animal base
var Animal = Fiber.extend(function(base) {
return {
// The `init` method serves as the constructor.
init: function() {
// Insert private functions here
function private1(){}
function private2(){}
// Insert priviledged functions here
this.privileged1 = function(){}
this.privileged2 = function(){}
},
method1: function(arguments){
console.log('animal::here! method1', this.s, this.result, arguments);
},
method2: function(arguments){
console.log('animal::here! method2', this.s, this.result, arguments);
}
}
});
// Extend the Animal class;
var Dog = Animal.extend(function(base) {
return {
init: function() {
console.log('Dog::init');
this.base = Fiber.proxy(this);
this.result = 123;
// Call the base init.
base.init.call(this);
},
// Override base class `method1`
method1: function(){
this.base.method1('hello');
this.method2();
console.log('Dog::method1', this.s);
},
scare: function(){
console.log('Dog::I scare you');
}
}
});
var mix1 = function(base) {
return {
something1: function() {
base.method1.call(this);
console.log('mixin:something1', this.s);
}
}
};
var mix2 = function(base) {
return {
something2: function() {
base.method1.call(this);
console.log('mixin:something2', this.s);
}
}
}
var husky = new Dog();
husky.scare(); // "Dog::I scare you'"
husky.s = 1;
Fiber.decorate(husky, function(base) {
this.blah = 1;
return {
scream: function() {
console.log('scream', base);
base.method1.call(this);
},
indeed: function() {
console.log('indeed', this.blah);
}
}
});
husky.indeed();
console.log('constructor', husky.constructor.__base);
husky.scream();
husky.blah;
Fiber.mixin(Dog, mix2);
husky.something2();
function dec(base) {
this.greet = function() {
this.hi();
}
}
var Parent = Fiber.extend(function() {
return {
init: function() {
console.log('init');
},
hi: function() {
console.log('hi');
}
}
});
var Child = Parent.extend(function(base) {
return {
init: function() {
base.init.call(this);
Fiber.decorate(this, dec);
}
}
});
var c = new Child();
c.greet();
</script>
</body>
</html>