When you are trying to develop a complex JavaScript application you will be looking for a way to organize and maintain your code in an easy way, that’s why Object Oriented Programming looks like the perfect approach. In OOP you can talk about public, private and privileged methods and members. Private methods and members have access the whole object but can’t be accessed by other objects. Public members and methods can’t access private parts but can be accessed by other objects. Finally privileged methods have full access to object and can be accessed by other objects.

The next technique can be used to write OOP in JavaScript:

1. Constructors are functions with the name of the object:

function Constructor(value) { ... };

2. Private members will be defined inside the constructor:

function Constructor(value) {
    var member = value;
};

3. Private methods will be defined inside the constructor:

function Constructor(value) {
    function Method() { ... }
    var Method = function() { ... }
};

4. Public members will be created inside the constructor and associated to this:

function Constructor(value) {
    this.member = value;
};

5. Public methods will be created outside the constructor using the prototype member of the object:

function Constructor(value) { ... };
Constructor.prototype.Method(){ ... }

6. Privileged methods will be created inside the constructor and associated to this:

function Constructor(value) {
    this.Method = function() { ... }
};