Skip to content

Instantly share code, notes, and snippets.

@zootella
Created March 4, 2013 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zootella/5085837 to your computer and use it in GitHub Desktop.
Save zootella/5085837 to your computer and use it in GitHub Desktop.
var makePerson = function (name, age) {
var me = {}, my = {};
//members
my.name = name;
my.age = age;
//private methods
my.incrementAge = function () {
my.age++;
}
//public methods
me.say = function () {
return my.name + ' is ' + my.age;
}
me.birthday = function () {
my.incrementAge();
}
return me;//return the me object, leave the my object private
};
var a;
a = makePerson('Adam', 3);
console.log(a.say()); //3
a.birthday();
console.log(a.say()); //4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment