Created
August 17, 2014 06:33
-
-
Save ryo-utsunomiya/48d2212bac16eb1b5436 to your computer and use it in GitHub Desktop.
javascript pattern: private member with constructor
This file contains hidden or 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
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