On Fri, 28 Nov 2008 22:42:45 +0100, Peter Michaux <[EMAIL PROTECTED]> wrote:
> The following suggests (i.e. could be interpreted as) a false Boolean
> object is a "truthy" value.
>
>> (new Boolean(false)) ? "a" : "b"
> "a"
Yes.
> The following suggests a false Boolean object is a "falsy" value
>
>> ((new Boolean(false)) == true) ? "a" : "b"
> "b"
It clearly shows that "new Boolean(false)" is not equal to "true".
However, there are lots of non-falsy values that are not equal to true, so I
don't
see it suggesting anything about the falsy-ness of "new Boolean(false)", any
more
than
((new String("pickles") == true) ? "a" : "b"
> I understand what is going on here but it seems like a bad state of affairs.
Wrapper objects are generally bad, if you ask me.
They serve no purpose, except as a specification device for allowing properties
on basic values.
> Does this need to be remedied? Can it be?
I don't think it is needed. The current rules are sometimes surprising, but
they are clear: all objects are considered true.
> It would be useful to have an object that is effectively "false" in an
> "if" conditional but which can also have properties like an object
> can.
If objects are no longer all "true", then I would prefer each object to
be able to decide its truth value.
However, it would probably break a lot of idiomatic constructs, like
if (obj) { obj.method(); }
or
var x = obj || defaultObj;
/L
--
Lasse R.H. Nielsen
'Faith without judgement merely degrades the spirit divine'
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss