Just one simple example about private and public methods in JavaScript.
Check this code in JS:
(function (ns) { function myCreator () { var self=this; function privateMethod() { alert("Hi I am private method and I can be executed only within myCreator class (I will be never called)"); } self.publicMethod = function () { document.getElementById("publicMethodCall").innerHTML = "Hi, I am called from publicMethod"; } } ns.myCreator = myCreator; }(window.privateAndPublic))
Here you can see how private method is declared:
function privateMethod
and public method:
self.publicMethod
When you open console and check what newly created object has, you will see that there is no privateMethod (because it is inaccessible):
Example download from here.