ryoakg
6/5/2016 - 2:53 PM

dom-type-hierarchy.html

<html>
  <head>
    <style>
     td { border-bottom: solid 1px #bbb; }
     th { border-bottom: solid 1.5px #3af; }
    </style>
  </head>
  <body>
    <table id="table">
      <tr><th>type name</th><th>expression</th></tr>
    </table>
    <script>
     Object.prototype.getName = function() {
       var funcNameRegex = /function (.{1,})\(/;
       var results = (funcNameRegex).exec((this).constructor.toString());
       return (results && results.length > 1) ? results[1] : "";
     };
     var table = document.getElementById('table');

     function p(expr){
       var tr = document.createElement('tr');
       table.appendChild(tr);

       var td1 = document.createElement('td');
       td1.textContent = eval(expr);
       tr.appendChild(td1);

       var td2 = document.createElement('td');
       td2.textContent = expr;
       tr.appendChild(td2);
     }

     for (var expr='document.body'; eval(expr); expr += '.__proto__')
       p(expr + '.getName()');
    </script>
  </body>
</html>