X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fxynt-base-test.js;fp=web%2Fxynt-base-test.js;h=2b45c7919bc7fe4b0653cffadd487e4c19f7ee49;hb=9f0cbf62feaea515635cfc85bddd5292b2170440;hp=0000000000000000000000000000000000000000;hpb=ff96d86813afe7c2d607bc6ca9d5c18c378c6fed;p=xynt.git diff --git a/web/xynt-base-test.js b/web/xynt-base-test.js new file mode 100644 index 0000000..2b45c79 --- /dev/null +++ b/web/xynt-base-test.js @@ -0,0 +1,139 @@ +function A(a, b) { + this.a_dyn = "A DYN"; + this.a = a; + this.b = b; +} + +A.prototype = { + a_stat: "A STAT", + + a_func: function () { + console.log("a_func run"); + }, + aa_func: function () { + console.log("aa_func run in A class"); + } +} + +function B(a, b) { + this.b_dyn = "B DYN"; + A.call(this, a, b); +} + +B.prototype = { + b_stat: "B STAT", + + a_func: function () { + console.log("a_func run from B"); + console.log("and now try to call the super method"); + this.callSuper("a_func"); + }, + + b_func: function () { + console.log("b_func run"); + } +} +function C() { + this.c_dyn = "C DYN"; +} + +C.prototype = { + c_stat: "C STAT", + + aa_func: function () { + console.log("aa_func run in C class"); + }, + + c_func: function () { + console.log("c_func run"); + } +} + +Extends(B, A); + +function print_dynstat(inst, name) +{ + for (i = 0 ; i < inst.length ; i++) { + console.log(name[i]+".a_dyn: "+inst[i].a_dyn); + console.log(name[i]+".a_stat: "+inst[i].a_stat); + if (name[i][0] == 'b') { + console.log(name[i]+".b_dyn: "+inst[i].b_dyn); + console.log(name[i]+".b_stat: "+inst[i].b_stat); + } + if (name[i][0] == 'c') { + console.log(name[i]+".c_dyn: "+inst[i].c_dyn); + console.log(name[i]+".c_stat: "+inst[i].c_stat); + } + } +} + +window.onload = function () { + console.log("Window.onload: begin"); + show_class(A); + show_class(B); + show_class(C); + + a1 = new A(1,2); + a2 = new A(3,4); + b1 = new B(5,6); + c1 = new C(); + + arr_inst = [ a1 , a2 , b1 , c1 ]; + arr_name = [ "a1", "a2", "b1", "c1" ]; + + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("ACTION: a1.a_stat = \"CHANGED\";"); + a1.a_stat = "CHANGED"; + + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED\""); + A.prototype.a_stat = "PROTO CHANGED"; + + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("ACTION: ExtendsInst(c1, A, [1, 33])"); + + var ext = ExtendsInst(c1, A, [1, 33]); + console.log("ExtInst: "+(ext == true ? "TRUE" : "FALSE")); +// } function azaz() { + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("ACTION: B.prototype.a_stat = \"PROTO CHANGED\""); + B.prototype.a_stat = "PROTO CHANGED"; + + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("ACTION: A.prototype.a_stat = \"PROTO CHANGED 2\""); + console.log("ACTION: C.prototype.c_stat = \"PROTO CHANGED 2\""); + A.prototype.a_stat = "PROTO CHANGED 2"; + C.prototype.c_stat = "PROTO CHANGED 2"; + + print_dynstat(arr_inst, arr_name); + + console.log("---"); + console.log("=== INSTANCE b1 ==="); + show_inst(b1); + console.log("=== INSTANCE b1.a_func() ==="); + b1.a_func(); + console.log("=== INSTANCE b1.b_func() ==="); + b1.b_func(); + + console.log("---"); + console.log("=== INSTANCE c1 ==="); + show_inst(c1); + console.log("=== INSTANCE c1.a_func() ==="); + c1.a_func(); + console.log("=== INSTANCE c1.aa_func() ==="); + c1.aa_func(); + console.log("=== INSTANCE c1.callSuper aa_func() ==="); + c1.callSuper("aa_func"); + console.log("=== INSTANCE c1.c_func() ==="); + c1.c_func(); +} \ No newline at end of file