一 代码
<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
本文通过三个实例详细介绍了JavaScript中Boolean对象的应用,包括创建Boolean对象、使用constructor和prototype属性以及使用toString()和valueOf()方法。
210

被折叠的 条评论
为什么被折叠?



