@ale152
Prova a dare una guardata qua, forse questo ti può essere utile…
codice:categorie = ["frutta", "verdura", "colore"]; // puoi aggiungerne a piacimento function Oggetto (sName, nCatId) { this.nome = sName; this.catId = nCatId; } Oggetto.prototype.getCategory = function() { return categorie[this.catId]; } Oggetto.prototype.toString = Oggetto.prototype.valueOf = function () { return this.nome; }; merce = [new Oggetto("carota", 1), new Oggetto("banana", 0), new Oggetto("rosso", 2)]; alert(merce[0]); // carota alert(merce[0].nome); // carota alert(merce[0].catId); // 1, ovvero verdura alert(merce[0].getCategory()); // verdura // sposto la carota da "verdura" a "colore" merce[0].catId = 2; alert(merce[0].catId); // 2, ovvero colore alert(merce[0].getCategory()); // colore![]()

Rispondi quotando
