ExtendsInst function added to extends a previous object
[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         if (name[i][0] == 'b') {
47             console.log(name[i]+".b_dyn: "+inst[i].b_dyn);
48             console.log(name[i]+".b_stat: "+inst[i].b_stat);
49         }
50         if (name[i][0] == 'c') {
51             console.log(name[i]+".c_dyn: "+inst[i].c_dyn);
52             console.log(name[i]+".c_stat: "+inst[i].c_stat);
53         }
54     }
55 }
56
57 window.onload = function () {
58     show_class(A);
59     show_class(B);
60     show_class(C);
61
62     a1 = new A(1,2);
63     a2 = new A(3,4);
64     b1 = new B(5,6);
65     c1 = new C();
66
67     arr_inst = [  a1 ,  a2 ,  b1 ,  c1  ];
68     arr_name = [ "a1", "a2", "b1", "c1" ];
69
70     print_dynstat(arr_inst, arr_name);
71
72     console.log("---");
73     console.log("ACTION: a1.a_stat = \"CHANGED\";");
74     a1.a_stat = "CHANGED";
75
76     print_dynstat(arr_inst, arr_name);
77
78     console.log("---");
79     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED\"");
80     A.prototype.a_stat = "PROTO CHANGED";
81
82     print_dynstat(arr_inst, arr_name);
83
84     console.log("---");
85     console.log("ACTION: ExtendsInst(c1, A, [1, 33])");
86
87     var ext = ExtendsInst(c1, A, [1, 33]);
88     console.log("ExtInst: "+(ext == true ? "TRUE" : "FALSE"));
89
90     print_dynstat(arr_inst, arr_name);
91
92     console.log("---");
93     console.log("ACTION: B.prototype.a_stat = \"PROTO CHANGED\"");
94     B.prototype.a_stat = "PROTO CHANGED";
95
96     print_dynstat(arr_inst, arr_name);
97
98     console.log("---");
99     console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED 2\"");
100     console.log("ACTION: C.prototype.c_stat = \"PROTO CHANGED 2\"");
101     A.prototype.a_stat = "PROTO CHANGED 2";
102     C.prototype.c_stat = "PROTO CHANGED 2";
103
104     print_dynstat(arr_inst, arr_name);
105
106     console.log("=== INSTANCE c1 ===");
107     show_inst(c1);
108     console.log("=== INSTANCE c1.a_func() ===");
109     c1.a_func();
110     console.log("=== INSTANCE c1.c_func() ===");
111     c1.c_func();
112 }