JSFiddle - React, Tailwind, and code Playground
JavaScript
var superPairs = [];
// An association list
// we can think of something more efficient latter.
var injectSuper = function (parent, child) {
superPairs.push({
parent: parent,
child: child
});
};
function $super(baseClass, obj){
for(var i=0; i < superPairs.length; i++){
var p = superPairs[i];
if(p.child === baseClass){
return p.parent;
}
}
}
var Top = {
foo: function(){
alert("you won");
}
};
var breaker = 0;
var Middle = Object.create(Top);
Middle.foo = function(){
alert("recursion " + breaker++);
if (breaker < 5) {
$super(Middle).foo.apply(this, arguments);
}
};
var Bottom = Object.create(Middle);
Bottom.foo = function(){
$super(Bottom).foo.apply(this, arguments);
};
injectSuper(Middle, Bottom);
injectSuper(Top, Middle);
Object.create(Bottom).foo();