first multiple inheritance working
[xynt.git] / prova.html
1 <html>
2 <head>
3 <script type="text/javascript" src="commons.js"></script>
4 <script type="text/javascript" src="xynt-dd.js"></script>
5 <script type="text/javascript" src="xynt-link.js"></script>
6 <script type="text/javascript">
7
8 function Adamo() {
9     this.name = "adamo";
10 }
11
12 Adamo.prototype = {
13     alupa: null,
14
15     pname: function()
16     {
17         console.log("NAME: "+this.name);
18     }
19 }
20
21 function Caino() {
22     this.super.constructor.call(this);
23     this.nname = "caino";
24 }
25
26 Caino.prototype = {
27     gojira: null,
28
29     pname2: function()
30     {
31         console.log("NAME:  "+this.name);
32         console.log("NNAME: "+this.nname);
33     }
34 }
35
36 function Extends_simple(sub, super)
37 {
38     var thinF = function(){};
39     thinF.prototype = super.prototype;
40     var tmp = new thinF();
41
42     for( var f in sub.prototype) {
43         tmp[f] = sub.prototype[f];
44         tmp['constructor'] = sub;
45     }
46     if( super.prototype.constructor == Object.prototype.constructor ){
47         super.prototype.constructor = super;
48     }
49     tmp['super'] = super.prototype;
50     sub.prototype = tmp;
51 }
52
53 Extends_simple(Caino, Adamo);
54
55 var c = new Caino();
56
57 console.log("A "+c.alupa);
58 console.log("G "+c.gojira);
59 console.log("U "+c.unko);
60
61 c.pname();
62 c.pname2();
63
64 function PreA() {
65     this.a_din = "adamo";
66 }
67
68 PreA.prototype = {
69     a_attr: "a attr content",
70     name: "PreA",
71
72     a_func: function()
73     {
74         console.log("A_NAME: "+this.a_din);
75         console.log("A_ATTR: "+this.a_attr);
76     }
77 }
78
79 function A() {
80     PreA.call(this);
81 }
82 A.prototype = {
83     name: "A"
84 }
85 Extends(A, PreA);
86
87 function B() {
88     this.b_din = "bonobo";
89 }
90
91 B.prototype = {
92     name: "B",
93     b_attr: "b attr content",
94
95     b_func: function()
96     {
97         console.log("B_NAME: "+this.b_din);
98         console.log("B_ATTR: "+this.b_attr);
99     }
100 }
101
102 function C() {
103     this.c_din = "canuca";
104 }
105
106 C.prototype = {
107     name: "C",
108     c_attr: "c attr content",
109
110     c_func: function()
111     {
112         console.log("C_NAME: "+this.c_din);
113         console.log("C_ATTR: "+this.c_attr);
114     }
115 }
116
117
118 function Summo() {
119     this.s_name = "caino";
120     A.call(this);
121     B.call(this);
122     C.call(this);
123
124 }
125
126 Summo.prototype = {
127     name: "Summo",
128     s_attr: null,
129
130     s_func: function()
131     {
132          this.a_func();
133          this.b_func();
134          this.c_func();
135          console.log("name: "+this.name);
136     }
137 }
138
139 Extends(Summo, A, B, C);
140
141 function Extends(sub)
142 {
143     var supers = [];
144
145     thinF = function(){};
146     tmp = new thinF();
147
148     console.log("INIZIO EXT");
149
150     var multi = function(sub, super, is_last)
151     {
152         var proto = super.prototype;
153
154         for (var f in proto) {
155             console.log("LOOP: "+f);
156             if( f != "constructor" && typeof(proto[f]) == "function" && is_last){
157                 console.log("PR: "+proto['name']+"  F: "+f);
158                 // sub[f] = proto[f];
159                 sub[f] = function(){
160                     console.log("INFU PR: " + proto['name'] + " FUNC: "+f);
161                     return proto[f].apply(this,arguments);
162                 }
163             }
164             else {
165                 console.log("PR: "+proto.name+"  A: "+f+" FUN: "+proto[f]);
166                 sub[f] = proto[f];
167             }
168         }
169     }
170
171     for( var i=1; i < arguments.length ; i++){
172         console.log("INIZIO LOOP");
173         multi(tmp, arguments[i], false);
174         supers.push(arguments[i].prototype);
175     }
176     multi(tmp, sub, true);
177     sub.prototype = tmp;
178 }
179
180 s_ist = new Summo();
181 s_ist.s_func();
182
183 </script>
184
185 </head>
186 <body>
187 <!-- task:begin -->
188 <div id="board" style="width: 1600; height: 800px; background-color: #f0f0f0; border: 1px solid black; position: relative;">
189   <div id="r1" style="width: 1600; height: 40px; left: 0px; top: 0px; background-color: #e8e8e8; border: 0px solid red; position: absolute;">
190     <div id="t1" style="z-index: 1; left: 10px; top: 10px; width: 100px; height: 21px; border: 1px solid gray; background-color: #c0c0ff; position: absolute;"></div>
191   </div>
192   
193   <div id="r2" style="width: 1600;  left: 0px; top: 40px; height: 40px; background-color: #e8e8ff; border: 0px solid red; position: absolute;">
194     <div id="t2" style="z-index: 1; left: 123px; top: 10px; width: 100px; height: 21px; border: 1px solid gray; background-color: #c0ffc0; position: absolute;"></div>
195   </div>
196
197   <div id="r3" style="width: 1600; height: 40px; left: 0px; top: 80px; background-color: #e8e8e8; border: 0px solid red; position: absolute;">
198     <div id="t3" style="z-index: 1; left: 10px; top: 10px; width: 100px; height: 21px; border: 1px solid gray; background-color: #c0c0ff; position: absolute;"></div>
199   </div>
200   
201   <div id="r4" style="width: 1600;  left: 0px; top: 120px; height: 40px; background-color: #e8e8ff; border: 0px solid red; position: absolute;">
202     <div id="t4" style="z-index: 1; left: 123px; top: 10px; width: 100px; height: 21px; border: 1px solid gray; background-color: #c0ffc0; position: absolute;"></div>
203   </div>
204   
205   <!-- task:end -->
206   
207   
208 </div>
209 </body>
210 </html>