Created
July 16, 2015 16:29
-
-
Save hellerve/59a7d3c4d1a7054ab7fb to your computer and use it in GitHub Desktop.
Private methods in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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