一 代码
<script language="javascript">
<!--
//第一组应用:创建Boolean对象
BoolObj1=newBoolean(false);
BoolObj2=newBoolean(0);
BoolObj3=newBoolean(null);
BoolObj4=newBoolean("");
BoolObj5=newBoolean();
BoolObj6=newBoolean(1);
BoolObj7=newBoolean(true);
document.write(BoolObj1+"<br>");
document.write(BoolObj2+"<br>");
document.write(BoolObj3+"<br>");
document.write(BoolObj4+"<br>");
document.write(BoolObj5+"<br>");
document.write(BoolObj6+"<br>");
document.write(BoolObj7+"<br>");
//第二组应用:constructor属性和prototype属性
var newBoolean8=newBoolean();
if(newBoolean8.constructor==Boolean)
{
document.write("布尔型对象");
document.write("<br>");
}
var newBoolean9=newBoolean();
Boolean.prototype.mark=null;//向对象中添加属性
newBoolean9.mard=1;//向添加的属性中赋值
document.write(newBoolean9.mard+"<br>");
//第三组应用:Boolean对象的toString()方法和valueOf()方法
var newBoolean10=newBoolean(1);
if(newBoolean10.toString()=="true")
{
document.write("true");
}
else
{
document.write("false");
}
document.write("<br>");
var newBoolean11=newBoolean();
newBoolean11=true;
document.write(newBoolean11.valueOf());
//-->
</script>
二 运行效果
false
false
false
false
false
true
true
布尔型对象
1
true
true
false
false
false
false
true
true
布尔型对象
1
true
true