Kod
function Screen(id, diagonal, x_resolution, y_resolution)
{
this.id = id;
this.diagonal = diagonal;
this.x_resolution = x_resolution;
this.y_resolution = y_resolution;
// tutaj reszta konstruktora
}
Screen.prototype.update = function(diagonal, x_resolution, y_resolution)
{
this = new Screen(this.id, diagonal, x_resolution, y_resolution);
}
{
this.id = id;
this.diagonal = diagonal;
this.x_resolution = x_resolution;
this.y_resolution = y_resolution;
// tutaj reszta konstruktora
}
Screen.prototype.update = function(diagonal, x_resolution, y_resolution)
{
this = new Screen(this.id, diagonal, x_resolution, y_resolution);
}
I nie działa (czego się spodziewałem:)).
Kod
invalid assignment left-hand side
[Break on this error] this = new Screen(this.id, diagonal, x_resolution, y_resolution);\n
[Break on this error] this = new Screen(this.id, diagonal, x_resolution, y_resolution);\n
Chcę napisać metodę, która będzie aktualizowała obiekt po wprowadzeniu nowych danych, właśnie przez wywołanie konstruktora. Wie ktoś jak to ładnie (i skutecznie:D) zrobić?