Read access to [[Class]]?

Rick Waldron waldron.rick at gmail.com
Fri Jan 27 10:32:10 PST 2012


Thanks to both of you, I wasn't aware that this was already documented in
an ES6 draft - my apologies.

Rick

On Fri, Jan 27, 2012 at 1:23 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Jan 27, 2012, at 9:59 AM, Rick Waldron wrote:
>
>
> On Fri, Jan 27, 2012 at 12:08 PM, Brendan Eich <brendan at mozilla.org>wrote:
>
>> [[Class]] begone in ES6.
>>
>
> Assuming the public facing API has no intention of breaking back
> compatibility, what internal property will be read to determine the return
> value of Object.prototype.toString (15.2.4.2)?
>
>
> The current ES6 draft defines its like this:
>
>
> *15.2.4.2 Object.prototype.toString ( )*
>
> When the *toString* method is called, the following steps are taken:
>
>    1. If the *this* value is *undefined*, return *"[object Undefined]"*.
>    2. If the *this* value is *null*, return *"[object Null]"*.
>    3. Let *O *be the result of calling ToObject passing the *this *value
>    as the argument.
>    4. If *O* has a [[NativeBrand]] internal property, let *tag* be the
>    corresponding value from the Table 23.
>    5. Else, let *tag* be the string value *"Object"*.
>    6. Return the String value that is the result of concatenating the
>    three Strings *"[object "*, *tag*, and *"]"*.
>
> *Table 23 — Tags for Classified Native Objects*
>   *[[NativeBrand]] Value*
>  *tag Value*
>   NativeFunction
>  *"Function"*
>   NativeArray
>  *"Array"*
>   StringWrapper
>  *"String"*
>   BooleanWrapper
>  *"Boolean"*
>   NumberWrapper
>  *"Number"*
>   NativeMath
>  *"Math"*
>   NativeDate
>  *"Date"*
>   NativeRegExp
>  *"RegExp"*
>   NativeError
>  *"Error"*
>   NativeJSON
>  *"JSON"*
>   NativeArguments
>  *"Arguments"*
>
>
> Basically, there is a fixed set of hardwired (to the spec.) object kinds
> that toString knows about. There is no implication that all objects must
> carry around an additional string value that is used to parameterize
> toString. If you want to extend an implementation with new built-in object
> kinds that toString recognizes then you must also extend your
> implementation of toString.
>
> [[Class]] has been treated by some as a mandatory implementation level
> extension point for adding new internal types, but it wasn't.
>
> Note that I have considered extending the above definition of toString
> with an explicit ES level extension point based using private names:
>
> If *O* has as well known private name property (think of it as:
> privateToStringTag) then *tag* is set to ToString of the value of that
> property.  This would happen between steps 4 and 5.
>
> Allen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120127/8bd03552/attachment-0001.html>


More information about the es-discuss mailing list