JavaScript手册 
目录
此参考中包含
的内容
轻松上手
简介
操作符
语句
核心
文档
窗口
表单
浏览器
事件和
事件句柄
LiveWire
数据库服务
进程管理服务
实用工具
全局函数
LiveConnect
的Java包
索引
版权
 
【目录】 【上一页】 【下一页】 【索引】

Boolean

The Boolean object is an object wrapper for a boolean value.

Core object
实现版本 Navigator 3.0, LiveWire 1.0

创建源

The Boolean constructor:

new Boolean(value)

参数

value The initial value of the Boolean object. The value is converted to a boolean value, if necessary. If value is omitted or is 0, null, false, or the empty string (""), the object has an initial value of false. All other values, including the string "false", create an object with an initial value of true.

描述

Use a Boolean object when you need to convert a non-boolean value to a boolean value. You can use the Boolean object any place JavaScript expects a primitive boolean value. JavaScript returns the primitive value of the Boolean object by automatically invoking the valueOf method.

属性概览

prototype Defines a 属性 that is shared by all Boolean objects.

方法概览

toString Returns a string representing the specified object.

示例

The following示例 create Boolean objects with an initial value of false:

bNoParam = new Boolean()
bZero = new Boolean(0)
bNull = new Boolean(null)
bEmptyString = new Boolean("")
bfalse = new Boolean(false)
The following示例 create Boolean objects with an initial value of true:

btrue = new Boolean(true)
btrueString = new Boolean("true")
bfalseString = new Boolean("false")
bSuLin = new Boolean("Su Lin")

属性

prototype

Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class. For information on prototypes, see Function.prototype.

属性源 Boolean
实现版本 Navigator 3.0, LiveWire 1.0

方法

toString

Returns a string representing the specified object.

方法源 Boolean
实现版本 Navigator 3.0, LiveWire 1.0

语法

toString()

参数

无。

描述

Every object has a toString method that is automatically called when it is to be represented as a text value or when an object is referred to in a string concatenation.

You can use toString within your own code to convert an object into a string, and you can create your own function to be called in place of the default toString method.

For Boolean objects and values, the built-in toString method returns "true" or "false" depending on the value of the boolean object. In the following code, flag.toString returns "true".

flag = new Boolean(true)
document.write("flag.toString() is " + flag.toString() + "<BR>")
For information on defining your own toString method, see the Object.toString method.


【目录】 【上一页】 【下一页】 【索引】

回页面顶部回页面顶部