some debugging statements removed
[xynt.git] / xynt-base.js
index 157141b..8c39a28 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * TODO
- *   super methods caller
- */
 
 function Extends(sub)
 {
@@ -11,7 +7,7 @@ function Extends(sub)
     inh.xynt_sup = [];
     inh.xynt_sup_cl = [];
 
-    console.log("INIZIO EXT");
+    console.log("EXT START");
 
     var multi = function(sub, super, is_last)
     {
@@ -23,10 +19,11 @@ function Extends(sub)
 
             console.log("LOOP: "+f);
             if( f != "constructor" && typeof(proto[f]) == "function" && !is_last){
-                console.log("M_FU: "+proto['name']+"  F: "+f);
+                console.log("M_FU: "+proto[f]+"  F: "+f);
                 // sub[f] = proto[f];
-                sub[f] = function(){
-                    console.log("INFU PR: " + proto['name'] + " FUNC: "+f+" THIS: " + this);
+                sub[f] = function() {
+                    // console.log("INFU PR: " + proto[f] + " FUNC: "+f+" THIS: " + this);
+                    console.log("SIMPLE LOG");
                     return proto[f].apply(this,arguments);
                 }
             }
@@ -44,6 +41,19 @@ function Extends(sub)
     }
 
     multi(inh, sub, true);
+
+
+    inh.callSuper = function(fnc){
+        var len = this.xynt_sup_cl.length;
+        for ( var i=0 ; i<len ; i++) {
+            var super = this.xynt_sup_cl[i];
+            if( (fnc in  super.prototype) && (typeof super.prototype[fnc] == "function") ){
+                return super.prototype[fnc].apply(this,[].splice.call(arguments,1));
+            }
+        }
+        return null;
+    }
+
     /*
     inh.superrr = function(cl, method) {
         console.log("xyx "+cl);
@@ -53,8 +63,7 @@ function Extends(sub)
     */
     sub.prototype = inh;
 
-    console.log(sub.prototype.xynt_sup);
-    console.log(sub.prototype.xynt_sup_cl);
+    console.log("EXT FINISH");
 }
 
 function ExtendsInst(sub)
@@ -73,11 +82,19 @@ function ExtendsInst(sub)
             sub.xynt_sup_cl = new Array();
 
         for (var f in proto) {
+            /* NOTE: this allow potentially TO BREAK by the extending class
+               if we disable it we don't have a reason to keep the callSuper function,
+               I need to meditate on it */
             if (f == "xynt_sup" || f == "xynt_sup_cl")
                 continue;
             
-            if (typeof(sub[f]) != 'undefined')
+            console.log("ExtensInst::multi: "+f+" type: "+typeof(sub[f]));
+            if (typeof(sub[f]) != 'undefined') {
+                if (typeof(sub[f]) == typeof(proto[f]))
+                    continue;
+                console.log("MULTI: false1");
                 return false;
+            }
 
             console.log("LOOP: "+f);
             if( f != "constructor" && typeof(proto[f]) == "function" && !is_last){
@@ -117,6 +134,17 @@ function ExtendsInst(sub)
         sub.xynt_sup_cl.push(cl);
     }
 
+    sub.callSuper = function(fnc){
+        var len = this.xynt_sup_cl.length;
+        for ( var i=0 ; i<len ; i++) {
+            var super = this.xynt_sup_cl[i];
+            if( (fnc in  super.prototype) && (typeof super.prototype[fnc] == "function") ){
+                return super.prototype[fnc].apply(this,[].splice.call(arguments,1));
+            }
+        }
+        return null;
+    }
+
     console.log("FINE EXT INST");
     return true;
 }
@@ -124,7 +152,8 @@ function ExtendsInst(sub)
 function show_class(cl) {
     console.log("Attributes Class of "+cl);
     for (f in cl.prototype) {
-        console.log(f+": ["+cl.prototype[f]+"]");
+        console.log(f+"-v");
+        console.log(cl.prototype[f]);
     }
     console.log("---");
 }
@@ -132,7 +161,8 @@ function show_class(cl) {
 function show_inst(inst) {
     console.log("Attributes Instance of "+inst);
     for (f in inst) {
-        console.log(f+": ["+inst[f]+"]");
+        console.log(f+"-v");
+        // console.log(inst[f]);
     }
     console.log("---");
 }