1.

What is the drawback of creating a true private in JavaScript?

Answer»

One of the drawbacks of creating a true private METHOD in JavaScript is that they are highly memory consuming. A new copy for each method is created for every instance.

Example:

var Employee = function (name, company, salary) {
    this.name = name || "";
    this.company = company || "";
    this.salary = salary || 5000;
    var increaseSlary = function () {
        this.salary = this.salary + 1000;
    };
    this.dispalyIncreasedSalary = function() {
       increaseSalary();
       console.log(this.salary);
   };
};
var emp1 = new Employee("Amar","Mars",3000);

Here, while creating each variable, each instance makes a new copy of emp1, emp2, and emp3 in IncreaseSalary. Thus, MAKING it INEFFICIENT for your SERVER end.



Discussion

No Comment Found