JSFiddle - React, Tailwind, and code Playground
by rudygotya
HTML
<div id="result"></div>
JavaScript
var foo = ( function () {
var foo = function () {
return new foo.prototype.init();
}
foo.prototype = {
constructor : foo,
init: function () {}
};
return foo;
} )();
var count = 0;
function getProtoDepth ( obj ) {
if( count > 100 ) {
return;
}
if( obj.constructor && obj.constructor.prototype ) {
count++;
if (obj.constructor.prototype.constructor ) {
getProtoDepth( obj.constructor.prototype.constructor )
}
}
return ( count > 100 ) ? "break on recursion": count ;
}
document.getElementById( "result" ).innerHTML = getProtoDepth( foo.prototype.constructor );