Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created July 2, 2012 04:50
Show Gist options
  • Select an option

  • Save renatoargh/3031158 to your computer and use it in GitHub Desktop.

Select an option

Save renatoargh/3031158 to your computer and use it in GitHub Desktop.
var personFactory = function(id, name, age){
var _id = id;
var _name = name;
var _age = age;
var personPrototype = {
getId: function(){
return _id;
},
setId: function(id){
_id = id;
},
getName: function(){
return _name;
},
setName: function(name){
_name = name;
},
getAge: function(){
return _age;
},
setAge: function(age){
_age = age;
}
};
return Object.create(personPrototype);
};
var renato = personFactory(1, "Renato Gama", 25);
console.log(renato.getName);
var foo = personFactory(2, "Foo Bar", 13);
console.log(foo.getName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment