Extens and ExtensInst completed
[xynt.git] / xynt-base-test4.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 }
14
15 function B(a, b) {
16     this.b_dyn = "B DYN";
17     A.call(this, a, b);
18 }
19
20 B.prototype = {
21     b_stat: "B STAT",
22
23     b_func: function () {
24         console.log("b_func run");
25     }
26 }
27 function C() {
28     this.c_dyn = "C DYN";
29 }
30
31 C.prototype = {
32     c_stat: "C STAT",
33
34     c_func: function () {
35         console.log("c_func run");
36     }
37 }
38
39 Extends(B, A);
40
41 function print_dynstat(inst, name)
42 {
43     for (i = 0 ; i < inst.length ; i++) {
44         console.log(name[i]+".a_dyn: "+inst[i].a_dyn);
45         console.log(name[i]+".a_stat: "+inst[i].a_stat);
46     }
47 }
48
49 window.onload = function () {
50     show_class(A);
51     show_class(B);
52     show_class(C);
53
54     a1 = new A(1,2);
55     a2 = new A(3,4);
56     b1 = new B(5,6);
57     c1 = new C();
58
59     arr_inst = [  a1 ,  a2 ,  b1 ,  c1  ];
60     arr_name = [ "a1", "a2", "b1", "c1" ];
61
62     print_dynstat(arr_inst, arr_name);
63
64     console.log("---");
65     console.log("ACTION: a1.a_stat = \"CHANGED\";");
66     a1.a_stat = "CHANGED";
67
68     print_dynstat(arr_inst, arr_name);
69
70     console.log("---");
71     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED\"");
72     A.prototype.a_stat = "PROTO CHANGED";
73
74     print_dynstat(arr_inst, arr_name);
75
76     console.log("---");
77     console.log("ACTION: ExtendsInst(c1, A, [1, 33])");
78
79     var ext = ExtendsInst(c1, A, [1, 33]);
80     console.log("ExtInst: "+(ext == true ? "TRUE" : "FALSE"));
81
82     print_dynstat(arr_inst, arr_name);
83
84     console.log("---");
85     console.log("ACTION: B.prototype.a_stat = \"PROTO CHANGED\"");
86     B.prototype.a_stat = "PROTO CHANGED";
87
88     print_dynstat(arr_inst, arr_name);
89
90     console.log("---");
91     console.log("ACTION: C.prototype.a_stat = \"PROTO CHANGED\"");
92     C.prototype.a_stat = "PROTO CHANGED";
93
94     print_dynstat(arr_inst, arr_name);
95
96     console.log("=== INSTANCE c1 ===");
97     show_inst(c1);
98     console.log("=== INSTANCE c1.a_func() ===");
99     c1.a_func();
100     console.log("=== INSTANCE c1.c_func() ===");
101     c1.c_func();
102 }