Question 3. What is the drawback of creating true private in JavaScript?
The "solution" says each copy of Employee will have its own copy of the increaseSalary and that such an implementation would be poor for memory. While that is true, it is also true that each instance of Employee would also have it's own copy of any properties or methods added to this. So in the case of your example, for the purposes of memory, increaseSalary is no different from dispalyIncreasedSalary in terms of memory consumption.
To actually be more memory efficient, one would want to put common properties and methods on the Employee prototype.
Question 3. What is the drawback of creating true private in JavaScript?
The "solution" says each copy of
Employee
will have its own copy of theincreaseSalary
and that such an implementation would be poor for memory. While that is true, it is also true that each instance ofEmployee
would also have it's own copy of any properties or methods added tothis
. So in the case of your example, for the purposes of memory,increaseSalary
is no different fromdispalyIncreasedSalary
in terms of memory consumption.To actually be more memory efficient, one would want to put common properties and methods on the
Employee
prototype.https://stackoverflow.com/questions/8433459/what-s-the-purpose-of-prototype