On Apr 11, 2011, at 6:45 PM, Axel Rauschmayer wrote:
>> var obj={}.valueOf.call(obj); // ToObject in case primitive value passed
>
> Can you explain how this works?
>
> - Why {} and not Object.prototype?
>
> - I know valueOf as a method that returns a primitive if an object can be
> converted to one and |this|, otherwise. Oddly enough, this works both in
> strict mode and in non-strict mode, as explained in the comment.
>
{}.valueOf is the same value as Object.prototype.valueOf assuming none of the
standard definitions have been over-written. See the comment thread of
http://www.wirfs-brock.com/allen/posts/166 for a debate as to which of these
forms is more or less optimizable.
Object.prototype.valueOf as specified is essentially a call to the internal
ToObject operation that wrappers primitive values. I put it in to deal with
cases like getDefiningObject("some string", "match")
Allen_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss