added new closure to cristalize the function name of the ancestor class to be called
[xynt.git] / xynt-base-test.js
1 function A(a, b) {
2     this.a_dyn = "A DYN";
3     this.a = a;
4     this.b = b;
5 }
6
7 A.prototype = {
8     a_stat: "A STAT",
9
10     a_func: function () {
11         console.log("a_func run");
12     },
13     aa_func: function () {
14         console.log("aa_func run in A class");
15     }
16 }
17
18 function B(a, b) {
19     this.b_dyn = "B DYN";
20     A.call(this, a, b);
21 }
22
23 B.prototype = {
24     b_stat: "B STAT",
25
26     a_func: function () {
27         console.log("a_func run from B");
28         console.log("and now try to call the super method");
29         this.callSuper("a_func");
30     },
31
32     b_func: function () {
33         console.log("b_func run");
34     }
35 }
36 function C() {
37     this.c_dyn = "C DYN";
38 }
39
40 C.prototype = {
41     c_stat: "C STAT",
42
43     aa_func: function () {
44         console.log("aa_func run in C class");
45     },
46
47     c_func: function () {
48         console.log("c_func run");
49     }
50 }
51
52 Extends(B, A);
53
54 function print_dynstat(inst, name)
55 {
56     for (i = 0 ; i < inst.length ; i++) {
57         console.log(name[i]+".a_dyn: "+inst[i].a_dyn);
58         console.log(name[i]+".a_stat: "+inst[i].a_stat);
59         if (name[i][0] == 'b') {
60             console.log(name[i]+".b_dyn: "+inst[i].b_dyn);
61             console.log(name[i]+".b_stat: "+inst[i].b_stat);
62         }
63         if (name[i][0] == 'c') {
64             console.log(name[i]+".c_dyn: "+inst[i].c_dyn);
65             console.log(name[i]+".c_stat: "+inst[i].c_stat);
66         }
67     }
68 }
69
70 window.onload = function () {
71     console.log("Window.onload: begin");
72     show_class(A);
73     show_class(B);
74     show_class(C);
75
76     a1 = new A(1,2);
77     a2 = new A(3,4);
78     b1 = new B(5,6);
79     c1 = new C();
80
81     arr_inst = [  a1 ,  a2 ,  b1 ,  c1  ];
82     arr_name = [ "a1", "a2", "b1", "c1" ];
83
84     print_dynstat(arr_inst, arr_name);
85
86     console.log("---");
87     console.log("ACTION: a1.a_stat = \"CHANGED\";");
88     a1.a_stat = "CHANGED";
89
90     print_dynstat(arr_inst, arr_name);
91
92     console.log("---");
93     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED\"");
94     A.prototype.a_stat = "PROTO CHANGED";
95
96     print_dynstat(arr_inst, arr_name);
97
98     console.log("---");
99     console.log("ACTION: ExtendsInst(c1, A, [1, 33])");
100
101     var ext = ExtendsInst(c1, A, [1, 33]);
102     console.log("ExtInst: "+(ext == true ? "TRUE" : "FALSE"));
103 // } function azaz() {
104     print_dynstat(arr_inst, arr_name);
105
106     console.log("---");
107     console.log("ACTION: B.prototype.a_stat = \"PROTO CHANGED\"");
108     B.prototype.a_stat = "PROTO CHANGED";
109
110     print_dynstat(arr_inst, arr_name);
111
112     console.log("---");
113     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED 2\"");
114     console.log("ACTION: C.prototype.c_stat = \"PROTO CHANGED 2\"");
115     A.prototype.a_stat = "PROTO CHANGED 2";
116     C.prototype.c_stat = "PROTO CHANGED 2";
117
118     print_dynstat(arr_inst, arr_name);
119
120     console.log("---");
121     console.log("=== INSTANCE b1 ===");
122     show_inst(b1);
123     console.log("=== INSTANCE b1.a_func() ===");
124     b1.a_func();
125     console.log("=== INSTANCE b1.b_func() ===");
126     b1.b_func();
127  
128     console.log("---");
129     console.log("=== INSTANCE c1 ===");
130     show_inst(c1);
131     console.log("=== INSTANCE c1.a_func() ===");
132     c1.a_func();
133     console.log("=== INSTANCE c1.aa_func() ===");
134     c1.aa_func();
135     console.log("=== INSTANCE c1.callSuper aa_func() ===");
136     c1.callSuper("aa_func");
137     console.log("=== INSTANCE c1.c_func() ===");
138     c1.c_func();
139 }