Read access to [[Class]]?
allen at wirfs-brock.com
Fri Jan 27 10:23:53 PST 2012
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 (126.96.36.199)?
The current ES6 draft defines its like this:
188.8.131.52 Object.prototype.toString ( )
When the toString method is called, the following steps are taken:
If the this value is undefined, return "[object Undefined]".
If the this value is null, return "[object Null]".
Let O be the result of calling ToObject passing the this value as the argument.
If O has a [[NativeBrand]] internal property, let tag be the corresponding value from the Table 23.
Else, let tag be the string value "Object".
Return the String value that is the result of concatenating the three Strings "[object ", tag, and "]".
Table 23 — Tags for Classified Native Objects
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss