Skip to content

Instantly share code, notes, and snippets.

@hellerve
Created July 16, 2015 16:29
Show Gist options
  • Save hellerve/59a7d3c4d1a7054ab7fb to your computer and use it in GitHub Desktop.
Save hellerve/59a7d3c4d1a7054ab7fb to your computer and use it in GitHub Desktop.
Private methods in JS
var myObj = (function() {
function myObj(something) {
this.something = something;
}
function privateMethod() {
console.log("private method called");
}
myObj.prototype.publicMethod = function() {
privateMethod();
};
return myObj;
})();
new myObj().publicMethod(); // yeah!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment