显示所有变量类型的构造器

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript constructor 属性</h2>
  6.  
  7. <p>constructor 属性返回变量或对象的构造器函数。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. document.getElementById("demo").innerHTML =
  13. "john".constructor + "<br>" +
  14. (3.14).constructor + "<br>" +
  15. false.constructor + "<br>" +
  16. [1,2,3,4].constructor + "<br>" +
  17. {name:'john', age:34}.constructor + "<br>" +
  18. new Date().constructor + "<br>" +
  19. function () {}.constructor;
  20. </script>
  21.  
  22. </body>
  23. </html>