I'm looking to call a constructor function dynamically based on an value I have in an object.
Let's say I have an object:
var food = {
pizzas:[
{
pizza: 'Pepperoni'
},
{
pizza: 'Vegetarian'
}
]
}
Now, let's say I have a couple of Constructor functions bound to a global object.
window.pizzaConstructors.Pepperoni = function(){
// do something
}
window.pizzaConstructors.Vegetarian = function(){
// do something else
}
What I want to be able to do is cycle through the food.pizzas
array and call the corresponding constructor function based on the type of pizza
of the current index.
So, if I have:
(for pizza in food.pizzas){
var currentPizza = food.pizzas[pizza]
new pizzaConstructors.currentPizza();
}
Any idea how I can go about this?