1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function Rectangle(x, y){
this.autreRectangle = [];
this.dx = 0;
this.dy = 0;
this.x = x;
this.y = y;
}
Rectangle.prototype = {
pas: function() {
this.dx += this.x+1;
this.dy += this.y+1;
this.autreRectangle.push(new Rectangle(this.dx, this.dy));
}
}
var rectangle = new Rectangle(200, 300);
rectangle.pas();
// liste des autres rectangles
console.log(rectangle.autreRectangle);
// augmenter le pas du premier rectangle au dessus
rectangle.autreRectangle[0].pas();
// rectangle de base
console.log(rectangle); |
Partager