Skip to content

Instantly share code, notes, and snippets.

@mdmartinez
Last active November 9, 2015 15:11
Show Gist options
  • Save mdmartinez/f63a0c359c4c0217319d to your computer and use it in GitHub Desktop.
Save mdmartinez/f63a0c359c4c0217319d to your computer and use it in GitHub Desktop.
var animal = {
animalType: 'animal'
};
function catFactory(name) {
var _name = name;
newCat = Object.create(animal);
newCat.animalType = 'cat';
newCat.setName = function(name) {
_name = name;
};
newCat.getName = function() {
return _name;
};
return newCat;
};
var myCat = catFactory("Mr. Jones");
myCat.animalType; // => "cat"
Object.getPrototypeOf(myCat).animalType; // => "animal"
myCat.getName(); // => "Mr. Jones"
myCat._name; // => undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment