>> Object wrappers are a minefield because they sometimes don't behave
>> the same as their primitive type. For example, eval() won't work if
>> called with a "new String" argument, and "new Boolean(false)"
>> evaluates to TRUE in a conditional context because it's an object.
>
> new Boolean(false) becomes false, but new Boolean('false') becomes true.
> Or did I get that wrong?
>
> http://www.jibbering.com/faq/faq_notes/type_convert.html#tcBool
It's not a type conversion, it's the object wrapping that causes havoc.
Boolean(false) returns its argument converted to a primitive boolean type;
new Boolean(false) converts its argument and wraps it in a Boolean object.
Copy/paste this into your favorite browser address bar:
javascript:b=Boolean(false); if(b) alert("true=="+b);else
alert("false=="+b);
Completely expected output, right? Now, add "new" to create a Boolean
object:
javascript:b=new Boolean(false); if(b) alert("true=="+b);else
alert("false=="+b);
Any object in a conditional context is considered to be true, even a Boolean
_object_ with a false value. However, when it comes time to print the value,
the .toString() method pulls out the actual value.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/