Why ES6 introduced classes yet `Symbol` not to be used with `new`?

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Aug 15 04:00:29 UTC 2016


Because, to be consistent with Number/String/Boolean you would expect `new Symbol()` to create a  Symbol wrapper object.  But we anticipated that if `new Symbol` was allowed many devs (who lacked an understanding of the difference between primitive values and wrapper objects for primitive values) would code `new Symbol()` with the expectation that they were creating a Symbol value. This would be a silent bug so we disallowed `new Symbol()`.

. 
> On Aug 14, 2016, at 4:15 PM, Domenic Denicola <d at domenic.me> wrote:
> 
> Symbol is not a class.
>  
> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of /#!/JoePea
> Sent: Sunday, August 14, 2016 18:31
> To: es-discuss <es-discuss at mozilla.org>
> Subject: Why ES6 introduced classes yet `Symbol` not to be used with `new`?
>  
> It seems like `new Symbol()` would be inline with the introduction of classes. Why was it chosen not to be constructible? Seems like it would make sense to throw an error on `Symbol()` but not `new Symbol()`. Was it to save three characters of typing?
> 
> /#!/JoePea
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

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


More information about the es-discuss mailing list