On Dec 30, 2007 7:19 PM, Cameron McCormack <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] ▪ ICQ 26955922 ▪ MSN [EMAIL PROTECTED]
>
>
--
Monkey, so they say, is the root of all people today.