Skip to content

Instantly share code, notes, and snippets.

@JasonDeving
Created March 16, 2016 04:32
Show Gist options
  • Save JasonDeving/28e720676df516477228 to your computer and use it in GitHub Desktop.
Save JasonDeving/28e720676df516477228 to your computer and use it in GitHub Desktop.
loop-through-constructor-with-forEach
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
},
name: name,
owner: "jason"
};
};
var animalNames = ["Sheep", "Liger", "Big Bird"];
var farm = [];
for(var i = 0; i < animalNames.length; i++) {
var animal = AnimalMaker(animalNames[i]);
farm.push(animal);
}
farm.forEach(function(animalNames){
console.log(animalNames.speak())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment