2007年3月9日星期五

(Javascript) About Boolean

from : http://www.blogjava.net/amigoxie/archive/2007/03/08/102655.html
(JavaScript的数值处理对象学习)

var booleanObj1= new Boolean( false);
var booleanObj2 = new Boolean(booleanObj1);
document.write("The booleanObj2 value is " + booleanObj2);

上面的代码,你认为结果会是什么呢?实际输出是:
The booleanObj2 value is true
是不是出乎你的意料?那么来看看下面的代码:

var booleanObj1 = new Boolean(false);
var booleanObj2 = new Boolean(booleanObj1);
// <=>
booleanObj2 = new Boolean(booleanObj1.toString());
// <=>
booleanObj2 = new Boolean("false");
// try:
booleanObj2 = new Boolean(booleanObj1. valueOf());
document.write("The booleanObj2 value is " + booleanObj2);

你理解了吗?

没有评论:

发表评论