Public Members and methods

The public members of the javascript object(class) are those which can be accessed by the instances of the parent object(base class). It can be illustrated by the following example

var baseClass = function(){
    this.member1 = "value"; //public member
   
    this.method1 = function(){ //public method
        // Code for the method
    }
}


The publicly accessible method can also be added using the prototype keyword also as illustrated below

baseClass.prototype.method2 = function(){
    //code goes here
}


The above methods is accessed as follows

var inherClass = new baseClass();
inherClass.method1(); // Method will be called
inherClass.method2(); // Method will be called

Private Members and methods

The private members and methods are those which cannot be accessed by the instances created from the base class. The private members can be created by the normal variable creation and normal function creation. When the this keyword is eliminated within the class then the member or method is said to be as private members.

var baseClass = function(){
    var member1 = "value"; //private member
   
    var method1 = function(){ //private method
        // Code for the method
    }
}


var inherClass = new baseClass();
inherClass.method1() // Will throw error


So here the private member cannot be accessed through the instance created from the base class.

Privileged methods

The public methods which can access the private members are called the privileged methods.

var baseClass = function(){
    var member1 = "value"; //private member
   
    var method1 = function(){ //private method
        // Code for the method
    }
    this.privMethod = function(){
        alert(member1); // Here private member is accessed within in the public method
    }

}

The privileged method can be accessed using the following ways

var inherClass = new baseClass();
inherClass.privMethod(); // Will alert the value of the private member.

So here the private member is accessed through the public method because the scope of the variable member1 is localized to the method using the concept of the closures so the execution of the privMethod doesn't throw any errors.