base-test.js added
[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     show_class(A);
72     show_class(B);
73     show_class(C);
74
75     a1 = new A(1,2);
76     a2 = new A(3,4);
77     b1 = new B(5,6);
78     c1 = new C();
79
80     arr_inst = [  a1 ,  a2 ,  b1 ,  c1  ];
81     arr_name = [ "a1", "a2", "b1", "c1" ];
82
83     print_dynstat(arr_inst, arr_name);
84
85     console.log("---");
86     console.log("ACTION: a1.a_stat = \"CHANGED\";");
87     a1.a_stat = "CHANGED";
88
89     print_dynstat(arr_inst, arr_name);
90
91     console.log("---");
92     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED\"");
93     A.prototype.a_stat = "PROTO CHANGED";
94
95     print_dynstat(arr_inst, arr_name);
96
97     console.log("---");
98     console.log("ACTION: ExtendsInst(c1, A, [1, 33])");
99
100     var ext = ExtendsInst(c1, A, [1, 33]);
101     console.log("ExtInst: "+(ext == true ? "TRUE" : "FALSE"));
102 // } function azaz() {
103     print_dynstat(arr_inst, arr_name);
104
105     console.log("---");
106     console.log("ACTION: B.prototype.a_stat = \"PROTO CHANGED\"");
107     B.prototype.a_stat = "PROTO CHANGED";
108
109     print_dynstat(arr_inst, arr_name);
110
111     console.log("---");
112     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED 2\"");
113     console.log("ACTION: C.prototype.c_stat = \"PROTO CHANGED 2\"");
114     A.prototype.a_stat = "PROTO CHANGED 2";
115     C.prototype.c_stat = "PROTO CHANGED 2";
116
117     print_dynstat(arr_inst, arr_name);
118
119     console.log("---");
120     console.log("=== INSTANCE b1 ===");
121     show_inst(b1);
122     console.log("=== INSTANCE b1.a_func() ===");
123     b1.a_func();
124     console.log("=== INSTANCE b1.b_func() ===");
125     b1.b_func();
126  
127     console.log("---");
128     console.log("=== INSTANCE c1 ===");
129     show_inst(c1);
130     console.log("=== INSTANCE c1.a_func() ===");
131     c1.a_func();
132     console.log("=== INSTANCE c1.aa_func() ===");
133     c1.aa_func();
134     console.log("=== INSTANCE c1.callSuper aa_func() ===");
135     c1.callSuper("aa_func");
136     console.log("=== INSTANCE c1.c_func() ===");
137     c1.c_func();
138 }