Read access to [[Class]]?

Axel Rauschmayer axel at rauschma.de
Sat Jan 28 14:18:36 PST 2012


> 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"


Not sure that it makes sense (backward compatibility...), but one could handle primitive booleans, numbers, and strings differently:

Currently:
    $ Object.prototype.toString.call(true)
    '[object Boolean]'
    
Alternative:
    $ Object.prototype.toString.call(true)
    '[primitive boolean]'


-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120128/a117a5d6/attachment-0001.html>


More information about the es-discuss mailing list