Last active
November 9, 2015 15:11
-
-
Save mdmartinez/f63a0c359c4c0217319d to your computer and use it in GitHub Desktop.
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
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