JS Boolean对象,用于转换非布尔型到布尔型,
例子:
<html> <body> <script type="text/javascript"> var b1=new Boolean( 0) var b2=new Boolean(1) var b3=new Boolean("") var b4=new Boolean(null) var b5=new Boolean(NaN) var b6=new Boolean("false") document.write("0 is boolean "+ b1 +"<br />") document.write("1 is boolean "+ b2 +"<br />") document.write("An empty string is boolean "+ b3 + "<br />") document.write("null is boolean "+ b4+ "<br />") document.write("NaN is boolean "+ b5 +"<br />") document.write("The string 'false' is boolean "+ b6 +"<br />") </script> </body> </html>
大家可以去运行以下
下面是一个比较全面的参考
Boolean Object Methods
FF: Firefox, N: Netscape, IE: Internet Explorer
Method | Description | FF | N | IE |
---|---|---|---|---|
toSource() | Represents the source code of an object | 1 | 4 | - |
toString() | Converts a Boolean value to a string and returns the result | 1 | 4 | 4 |
valueOf() | Returns the primitive value of a Boolean object | 1 | 4 | 4 |
Boolean Object Properties
Property | Description | FF | N | IE |
---|---|---|---|---|
constructor | A reference to the function that created the object | 1 | 2 | 4 |
prototype | Allows you to add properties and methods to the object | 1 | 2 | 4 |