Have an object to which you can also attach functions. In order to have several Flower objects, you need to use the following: you can easily create new Flowers, and all of them will have functions that you added:
function Flower(price, color, height){ this.price = price; this.color= color; this.height= height; this.myfunction = function() { alert(this.color); } } var fl = new Flower(12, "green", 65); fl.color = "new color"); alert(fl.color); fl.myfunction();
If you want some kind of array to just use an object literal, but you need to set properties and functions for each object you create.
var flower = { price : 12, color : "green", myfunction : function(){ alert(this.price); } }; flower.price = 20; alert(flower.price); alert(flower.myfunction());
Niels
source share