Salve, il mio dubbio è sulla creazione di classi e uso di metodi indipendentemente dal linguaggio di programmazione (nel mio caso sto usando javascript).
E' giusto il modo in cui ho creato le due classi? Oppure c'è troppa dipendenza tra la classe geometry e vertice perchè all'interno di geometry c'è il campo di tipo vertice?codice:////////////////////////////////////////// // VERTICES ////////////////////////////////////////// function Vertice(x, y, z) { this.x = x; this.y = y; this.z = z; } Vertice.prototype.show = function () { return this.x + ":" + this.y + ":" + this.z; } ////////////////////////////////////////// // GEOMETRY ////////////////////////////////////////// function Geometry() { this.vertice = []; } Geometry.prototype.push = function(v) { this.vertice.push(v); } Geometry.prototype.show = function() { for(var i = 0; i < this.getVerticeCount(); i++){ this.vertice[i].show();// undefined! } } Geometry.prototype.getVerticeCount = function() { return this.vertice.length; } /////TEST///// function test() { v = new Vertice(2,4,6); console.log(v.show()); g = new Geometry(); g.push(v); console.log(g .show()); //undefined }

Rispondi quotando
