JavaScript Number constructor 属性


定义和用法

constructor 属性返回对创建此对象的 Boolean 函数的引用。

语法
  1. object.constructor

实例

在本例中,我们将展示如何使用 constructor 属性:

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. var test=new Number();
  5. if (test.constructor==Array)
  6. {
  7. document.write("This is an Array");
  8. }
  9. if (test.constructor==Boolean)
  10. {
  11. document.write("This is a Boolean");
  12. }
  13. if (test.constructor==Date)
  14. {
  15. document.write("This is a Date");
  16. }
  17. if (test.constructor==String)
  18. {
  19. document.write("This is a String");
  20. }
  21. if (test.constructor==Number)
  22. {
  23. document.write("This is a Number");
  24. }
  25. </script>
  26. </body>
  27. </html>

输出:

  1. This is a Number

分类导航