Super recursion problem with method

by ZenMaster

JavaScript

function A() {}
A.prototype.foo = function() {
    console.log('A');
};
var counter = 0;

function B() {}
B.prototype = Object.create(A.prototype);
B.prototype.constructor = B;
B.prototype.$super = function(){ return A.prototype; };
B.prototype.foo = function() {
    if (counter < 3) {
        counter++;
        console.log(counter, 'B');
        return this.$super().foo.call(this, arguments);
    }

};

function C() {}
C.prototype = Object.create(B.prototype);
C.prototype.constructor = C;
C.prototype.$super = function(){ return B.prototype; };
C.prototype.foo = function() {
    console.log('C');
    return this.$super().foo.call(this, arguments);
};


new C().foo();