On Fri, Dec 7, 2012 at 10:12 AM, Erik de Bruin <e...@ixsoftware.nl> wrote:

> [#Changes:
> - don't create private vars on the prototype, instead 'create' them in
> the constructor (as this._privateVar), as shown in the example
>
> I'm not sure which example you refer to. But what is the difference, if
you still assign the value to this._privateVar?
The real difference is whether the right-hand side of the assignment is a
constant, immutable value. Then you can safely add the value to the
prototype and even save some memory at runtime (while losing a microsecond
for prototype-chain-lookup). However, if it is a dynamic expression or
evaluated to a mutable object (like e.g. an Array), you have to make sure
that every object instance receives its own fresh instance, and so the
assignment has to be placed in the constructor.

Reply via email to