On Jan 27, 2012, at 9:59 AM, Rick Waldron wrote:

> 
> On Fri, Jan 27, 2012 at 12:08 PM, Brendan Eich <[email protected]> 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:

        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

[[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
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to