I can't find a set of google search terms that answer this question. Is there a javascript equivalent to PHP's __construct function, i.e. a function that runs automatically whenever the object is instantiated?
var pizza = {
var crust,
** instantiate? **: function(){
this.crust = true;
},
topping: function(myTopping){
this.crust += myTopping;
},
bake: function(){
alert('done!');
}
}
var mypizza = new pizza(); // << crust is added right away, internally
mypizza.topping('pepperoni');
mypizza.topping('green pepper');
mypizza.topping('onion');
mypizza.bake();