Skip to content

Instantly share code, notes, and snippets.

@ryo-utsunomiya
Created August 17, 2014 06:33
Show Gist options
  • Save ryo-utsunomiya/48d2212bac16eb1b5436 to your computer and use it in GitHub Desktop.
Save ryo-utsunomiya/48d2212bac16eb1b5436 to your computer and use it in GitHub Desktop.
javascript pattern: private member with constructor
function Gadget() {
// private member
var name = 'iPod';
// public member
this.getName = function () {
return name;
};
}
var toy = new Gadget();
console.log(toy.name); // undefined
console.log(toy.getName()); // 'iPod'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment