如何列出[object HTMLParagraphElement] / Convert [object HTMLParagraphElement] to Object的所有属性?

时间:2016-08-10 14:54:01

标签: javascript html5 dom

如何列出此对象中的所有属性和函数,如htmlCollection / HTMlParagraphElement / document对象?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>DOM</title>
  </head>
  <body>
    <script type="text/javascript">
      document.addEventListener('DOMContentLoaded', function() {
        var getByTag = function(selector) {
          // FIXME: Do more conditions -- Come Up with more non-verbose regex condition
          return /\w/i.test(selector) ? document.getElementsByTagName(selector) : null;
        }
        var isHTMLCollection = function(data) {
          return data.toString() === '[object HTMLCollection]';
        }
        var toArray = function(c) {
          return Array.prototype.slice.call(c);
        }
        var getAllPs = getByTag('p');
        console.log(getAllPs, 'getAllPs');
        console.log(isHTMLCollection(getAllPs), 'isHTMLCollection');
        var _arrayLike = toArray(getAllPs);
        _arrayLike.map((node) => {
          console.log(node.toString(), 'typeof node');
          window.__node = node;
        });
      });
    </script>
    <p id="p1">
      First Para
    </p>
    <p id="p2">
      Second Para
    </p>
  </body>
</html>

正如您所看到的,我将节点分配给窗口对象并使用该对象控制台查看所有道具和函数。

有没有办法打印/记录所有道具和功能?

Console-Chrome

0 个答案:

没有答案