Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.arcetri.astro.it/irlab/doc/library/javascript/clientreference/boolean.htm
Дата изменения: Thu Oct 7 13:13:38 1999 Дата индексирования: Sat Dec 22 14:29:28 2007 Кодировка: Поисковые слова: ceres |
Boolean
object is an object wrapper for a boolean value.
JavaScript 1.3: added | |
Boolean
constructor:
new Boolean(value)
value |
undefined
or null
, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement. For example, the condition in the following if
statement evaluates to true
:
x = new Boolean(false);This behavior does not apply to Boolean primitives. For example, the condition in the following
if(x) //the condition is true
if
statement evaluates to false
:
x = false;Do not use a
if(x) //the condition is false
Boolean
object to convert a non-boolean value to a boolean value. Instead, use Boolean as a function to perform this task:
x = Boolean(expression) //preferredIf you specify any object, including a Boolean object whose value is false, as the initial value of a Boolean object, the new Boolean object has a value of true.
x = new Boolean(expression) //don't use
myFalse=new Boolean(false) // initial value of falseIn JavaScript 1.3 and later versions, do not use a Boolean object in place of a Boolean primitive.
g=new Boolean(myFalse) //initial value of true
myString=new String("Hello") // string object
s=new Boolean(myString) //initial value of true
Boolean
object is used as the condition in a conditional test, JavaScript returns the value of the Boolean
object. For example, a Boolean
object whose value is false is treated as the primitive value false, and a Boolean
object whose value is true is treated as the primitive value true
in conditional tests. If the Boolean
object is a false
object, the conditional statement evaluates to false
.
Property |
Description
|
| |
---|
watch
and unwatch
methods from Object
.
Boolean
objects with an initial value of false:
bNoParam = new Boolean()The following examples create
bZero = new Boolean(0)
bNull = new Boolean(null)
bEmptyString = new Boolean("")
bfalse = new Boolean(false)
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")
Object.constructor
.
Function.prototype
.toSource()
toSource
method returns the following values:
function Boolean() {
[native code]
}
Boolean
, toSource
returns a string representing the source code.
Object.toSource
toString()
Boolean
object overrides the toString
method of the Object
object; it does not inherit Object.toString
. For Boolean
objects, the toString
method returns a string representation of the object.
JavaScript calls the toString
method automatically when a Boolean is to be represented as a text value or when a Boolean is referred to in a string concatenation.
For Boolean
objects and values, the built-in toString
method returns the string "true"
or "false"
depending on the value of the boolean object. In the following code, flag.toString
returns "true"
.
var flag = new Boolean(true)
var myVar=flag.toString()
Object.toString
valueOf()
valueOf
method of Boolean
returns the primitive value of a Boolean object or literal Boolean as a Boolean data type.
This method is usually called internally by JavaScript and not explicitly in code.
x = new Boolean();
myVar=x.valueOf() //assigns false to myVar
Object.valueOf
Last Updated: 05/28/99 11:59:04