Re: [Bindings] stringify

> On Dec 30, 2007 7:19 PM, Cameron McCormack <cam@mcc.id.au> wrote:
> > 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]

On 31/12/2007, Garrett Smith <dhtmlkitchen@gmail.com> wrote:
> 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 )


It uses the global object if the first argument is not what the
ECMAScript spec calls "an object". The only things in ECMAScript that
are not "an object" are null and undefined. Those should be handled by
user code respectively. Anyone who knows ECMAScript well enough to
know about Function.prototype.call and function.prototype.apply
probably knows this. In any case, that's entirely the domain of
ECMAScript and not the DOM bindings, IMO.

> On Dec 30, 2007 7:19 PM, Cameron McCormack <cam@mcc.id.au> wrote:
> > You can rely on the string between "[object " and "]" to be the
> > [[Class]] of the object.  (Well, assuming Object hasn't been changed.)

I think ES4 will make the standard library global constructor object
bindings {ReadOnly, DontDelete}, but IIRC there's been some discussion
that it might break more scripts than it helps, so it might not
happen.
-- 
David "liorean" Andersson

Received on Monday, 31 December 2007 12:44:28 UTC