W3C home > Mailing lists > Public > public-webapi@w3.org > May 2008

Re: [WebIDL] ToString( Null ) => "null" :: Ecma-262 r3

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Tue, 27 May 2008 16:29:10 -0700
Message-ID: <c9e12660805271629h120494d5r48726e7042fca775@mail.gmail.com>
To: "Jonas Sicking" <jonas@sicking.cc>
Cc: public-webapi@w3.org, "Maciej Stachowiak" <mjs@apple.com>, "Ian Hickson" <ian@hixie.ch>, "Anne van Kesteren" <annevk@opera.com>

On Tue, May 27, 2008 at 3:38 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>

Hey Jonas,

> Granted, this is partially due to a javascript spec "bug", null really
> should have serialized to "" rather than "null".
>

The value null, when passed to ToString, converts to the string
literal "null". I don't agree that that's a bug. This is how the
language was designed and I think it was a right choice. Other
programming languages use this approach, too. I think it is intuitive
because:

var el = document.getElementById( arg );
console.log( el );

- will print "null" to the console, if arg is not found (resulting in
el being null). This is useful.

It is very simple, when desired, to do:-

if(s === null) s = "";

It would seem wrong for null to convert to the string "" when passed
to ToString.

I don't suppose you'd rather have ToString( Undefined ) to result in
"undefined"?

Garrett
Received on Tuesday, 27 May 2008 23:29:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 May 2008 23:29:54 GMT