Arto8 PHP


Multi inheritance prototype

arto8('', 'arto.prototype', function(prototype) {
    var A = prototype(),
        B = prototype(),
        AB = prototype(A, B),
        C = prototype(AB),
        D = prototype(A, B);

    function Foo() {};
    // Created Foo contructor for objects and after prototype created with .create() method
    Foo.prototype = C.create();
    
    var obj = new Foo();

    // all methods must added to the prototype only .extend(...) method
    A.extend({
        foo: function() {
            console.log('A.foo');
        }
    });
    obj.foo();  // output A.foo
    
    AB.extend({
        foo: function() {
            console.log('AB.foo');
        }
    });
    obj.foo();  // output AB.foo
    
    B.extend({
        foo: function() {
            console.log('B.foo');
        }
    });
    obj.foo();  // output AB.foo - becouse child AB prototype has owner foo method

    console.log(AB.hasOwnProperty('foo'));  //  output true - check owner property with this method
    AB.remove('foo');   //  delete property only with this method
    console.log(AB.hasOwnProperty('foo'));  //  output false
    obj.foo();  //  output B.foo - this time child AB owner foo method removed and 
                //  inherited most right B prototype method. 
            
    B.extend({
        foo1: function() {
            console.log('B.foo1');
        }
    });
    obj.foo1();
    
    C.extend({
        foo: function() {
            console.log('C.foo');
        }
    });
    obj.foo();
    
    // javascript instanceof operator not worked, instead must use .arto.is(...) method 
    console.log(obj.arto.is(A));
    console.log(obj.arto.is(AB));
    console.log(obj.arto.is(C));
    console.log(obj.arto.is(D));
});            
A.foo
AB.foo
AB.foo
true
false
B.foo
B.foo1
C.foo
true
true
true
false