當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。