Why are non-method properties in a prototype an anti-pattern?
andrea.giammarchi at gmail.com
Wed Nov 7 09:25:09 PST 2012
You are thinking in "constructors" ... I think in
`Object.create(fromObject)` where there's no initialization and defaults
are more than welcome. There is no reason to assign all possible defaults
per each instance creation ... it's "costy" so why would you ? I prefer
assign/overwrite properties when needed, not because the language requires
me doing it, you know what I mean :-)
On Wed, Nov 7, 2012 at 9:17 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
> In theory, one can use prototype properties to provide default values for
> instance properties. In practice, that is not often useful, because the
> constructor normally creates all instance properties right away, assigning
> default values where necessary. And, with default parameter values in ES6
> that is even easier to do.
> As mentioned by Andrea in another thread, another argument against
> non-method prototype properties is that they prevent you from freezing the
> prototype (because that would make assigning to instance properties
> Any other reasons for why they are discouraged?
> Dr. Axel Rauschmayer
> axel at rauschma.de
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss