Created
March 16, 2016 04:32
-
-
Save JasonDeving/28e720676df516477228 to your computer and use it in GitHub Desktop.
loop-through-constructor-with-forEach
This file contains 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
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