Skip to content

Instantly share code, notes, and snippets.

@erikroyall
Last active December 17, 2015 02:48
Show Gist options
  • Save erikroyall/5538077 to your computer and use it in GitHub Desktop.
Save erikroyall/5538077 to your computer and use it in GitHub Desktop.
JavaScript Private Properties and Methods in Object- Oriented Programming
window.erik = (function(){
var Erik, erik;
Erik = function() {
this.name = "Erik Royall";
this.age = 14;
};
return erik = {
// Public Method
getName: function() {
var e = new Erik();
return e.name;
}
};
}());
console.log(erik.getName()); // "Erik Royall"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment