无涯教程-Javascript - constructor函数

61 阅读1分钟

构造函数返回对创建原型的字符串函数的引用。

constructor - 语法

string.constructor

constructor - 返回值

返回创建此对象的函数。

constructor - 示例

<html>
   <head>
      <title>JavaScript String constructor Method</title>
   </head>
   
   <body>   
      <script type="text/javascript">
         var str=new String( "This is string" );
         document.write("str.constructor is:" + str.constructor); 
      </script>      
   </body>
</html>

运行上面代码输出

str.constructor is: function String() { [native code] } 

参考链接

www.learnfk.com/javascript/…