जावास्क्रिप्ट में सही मायने में निजी तरीके बनाने से प्रत्येक वस्तु के पास फ़ंक्शन की अपनी प्रति होती है। ये प्रतियाँ तब तक कूड़ा-करकट नहीं होतीं जब तक कि वस्तु स्वयं नष्ट न हो जाए।
उदाहरण
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);