W3C home > Mailing lists > Public > public-webapi@w3.org > December 2007

Re: [Bindings] stringify

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Mon, 31 Dec 2007 01:34:49 -0800
Message-ID: <c9e12660712310134m7b00436fib178357720492916@mail.gmail.com>
To: "Web API WG (public)" <public-webapi@w3.org>
On Dec 30, 2007 7:19 PM, Cameron McCormack <cam@mcc.id.au> wrote:
>
> Hi Garrett.
>
> Garrett Smith:
> > Checking an object's toString return value to try and determine what
> > it is is not a reliable way to check what type of object it is:
> > toString() says nothing about an object's interface, other than the
> > fact that, if no error is thrown, it supports toString().
> >
> > For example:
> > "[object Window]".toString()
> >
> > Method toString is useful for providing a readable representation of
> > an object's state. In ES, as David said, it's "[object " + [[Class]] +
> > "]".
>
> You can however use Object.prototype.toString.call() to ensure you are
> getting Object's version of toString(), and not some overridden version:
>
>   >>> Object.prototype.toString.call("[object Window]")
>   [object String]
>

Yeah, that is true.

But not 100% foolproof:
Function.prototype.call uses the calling context when arg0 is undefined or null.

Object.prototype.toString.call( undefined )
Object.prototype.toString.call( null )


> You can rely on the string between "[object " and "]" to be the
> [[Class]] of the object.  (Well, assuming Object hasn't been changed.)
>
> --
>
> Cameron McCormack, http://mcc.id.au/
>         xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au
>
>



-- 
Monkey, so they say, is the root of all people today.
Received on Monday, 31 December 2007 09:34:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:59 GMT