当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


javascript Boolean constructor用法及代码示例


在JavaScript中,构造函数属性返回对象的构造函数。对于JavaScript布尔值,构造函数属性返回函数Boolean() {[native code]}。

用法:

boolean.constructor

返回值:它返回函数Boolean() {[native code]}。


范例1:此示例说明了布尔构造函数属性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        JavaScript Boolean constructor Property 
    </title> 
</head> 
  
<body style="text-align:center;"> 
  
    <div style="background-color:green;"> 
              
        <h1>Welcome to GeeksforGeeks!.</h1> 
                  
        <p> 
            It returns the function that created 
            the boolean's prototype:
        </p> 
                  
        <h1 id="GFG"></h1> 
          
    </div> 
      
    <!-- Script to use boolean constructor -->
    <script> 
        var bool = false; 
        document.getElementById("GFG").innerHTML 
                = bool.constructor; 
    </script> 
</body> 
  
</html>                    

输出:

范例2:此示例说明了布尔构造函数属性。

<!DOCTYPE html> 
<html> 
      
<head> 
    <title> 
        JavaScript Boolean constructor Property 
    </title> 
</head> 
  
<body style="text-align:center;"> 
  
    <div style="background-color:white;"> 
          
        <h1>Welcome to GeeksforGeeks!.</h1> 
          
        <h3> 
            It returns the function that created 
            the boolean's prototype:
        </h3> 
          
        <p id="name" style="background-color:green;"></p> 
    </div> 
      
    <!-- Script to use Boolean constructor Property -->
    <script> 
        var bool = false; 
        document.getElementById("name").innerHTML 
                = bool.constructor; 
    </script> 
</body> 
  
</html>                    

输出:



相关用法


注:本文由纯净天空筛选整理自AdeshSingh1大神的英文原创作品 JavaScript | Boolean constructor Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。