Define static properties and prototype properties with the class syntax

Frankie Bagnardi f.bagnardi at gmail.com
Sat Dec 13 00:57:33 PST 2014


The case against it is it only works with primitives.  If you set an
object/array on the prototype it's shared by all instances, which is
dangerous.

On Fri, Dec 12, 2014 at 10:15 PM, Glen Huang <curvedmark at gmail.com> wrote:

> I agree data properties on the instance prototype is a bad idea. But
> static properties are really useful. Could we at lease allow them:
>
> class Foo {
>   static bar = 43;
> }
>
> On Dec 13, 2014, at 12:53 PM, Kevin Smith <zenparsing at gmail.com> wrote:
>
> function Foo() {}
>> Foo.bar = 1;
>> Foo.prototype.baz = 2;
>>
>> Is it possible to allow this in es6 with the class syntax? Or it belongs
>> to es7? Or it’s simply a terrible idea?
>>
>
> Data properties on the instance prototype are generally considered to be a
> footgun.  If you want to expose a data-like property on the constructor (or
> the instance prototype), you can use accessors:
>
>     let _bar = 1;
>     class Foo {
>         static get bar() { return _bar; }
>         static set bar(value) { _bar = value; }
>     }
>     Foo.bar = 43;
>
>
>
> _______________________________________________
> 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/20141213/678a9773/attachment.html>


More information about the es-discuss mailing list