Javascript에서 진정한 개인 메서드를 만들면 각 개체에 고유한 함수 복사본이 생깁니다. 이러한 복사본은 개체 자체가 파괴될 때까지 가비지 수집되지 않습니다.
예시
var Student = function (name, marks) {
this.name = name || ""; //Public attribute default value is null
this.marks = marks || 300; //Public attribute default value is null
// Private method
var increaseMarks = function () {
this.marks = this.marks + 10;
};
// Public method(added to this)
this.dispalyIncreasedMarks = function() {
increaseMarks();
console.log(this.marks);
};
};
// Create Student class object. creates a copy of privateMethod
var student1 = new Student("Ayush", 294);
// Create Student class object. creates a copy of privateMethod
var student2 = new Student("Anak", 411);