JSFiddle - React, Tailwind, and code Playground

by amatiasq

HTML

<script src="http://amatiasq.com/fiddle-console.js"></script>

JavaScript

function $extends(base, methods) {
    var obj = Object.create(base);
    for (var i in methods)
        if (methods.hasOwnProperty(i))
            obj[i] = methods[i];
    obj.super = base;
    return obj;
}
var count = 0;

var A = $extends(null, {
    init: function() {
        console.log('A.init()');
    }
});
var B = $extends(A, {
    init: function() {
        count++;
        if (count > 100)
            throw new Error('Infinite recursion');
        
        console.log('B.init()');
        // we expect this.super (or this.$super) to be A
        // because B.super is A
        this.super.init.call(this);
    }
});
var C = $extends(B, {
    init: function() {
        console.log('C.init()');
        // this.super is B, because C.super is B
        // then from here we invoke this.super.init.call(this);
        this.super.init.call(this);
        // but wait! B.init is also invoking `this.super.init.call(this)`
        // as `this` prototypes C `this.super` is B, even inside B.init
        // So when B.init invokes `this.super.init.call(this)` its invoking itself
    }
});

var a = Object.create(C);
a.init();