Inverted Inheritance Test

by Julien Gobin

JavaScript

TEST = function() {};

TEST.Node = function() {
    console.log("TEST.Node");
    this.cache = {};
    this.updateCache();
};

TEST.Node.prototype.updateCache = function () {
    if(this.constructor._super) {
       console.log("this.constructor._super", this.constructor._super);
       this.constructor._super.prototype.updateCache.call(this);
    }
    
    this._updateCache();
};

TEST.Node.prototype._updateCache = function () {
    console.log("TEST.Node.prototype._updateCache");
};
//////////////////////
TEST.Camera = function() {
    console.log("TEST.Camera");
    this.constructor._super = TEST.Node;
    this.constructor._super.call(this);
    console.log("Camera.cache", this.cache);
    this.alpha = 2;
    this._updateCache();
    console.log("Camera.cache", this.cache);
};

TEST.Camera.prototype = Object.create(TEST.Node.prototype);

TEST.Camera.prototype._updateCache = function () {
    console.log("TEST.Camera.prototype._updateCache");
    this.cache.alpha = this.alpha;
};
/////////////////
TEST.ArcRotateCamera = function() {
    console.log("TEST.ArcRotateCamera");
    this.constructor._super = TEST.Camera;
    this.constructor._super.call(this);
    console.log("ArcRotateCamera.cache", this.cache);
    this.beta = 2;
    this._updateCache();
    console.log("ArcRotateCamera.cache", this.cache);
};

TEST.ArcRotateCamera.prototype = Object.create(TEST.Camera.prototype);

TEST.ArcRotateCamera.prototype._updateCache = function () {
    console.log("TEST.ArcRotateCamera.prototype._updateCache");
    this.cache.beta = this.beta;
};

window.c;