When setting up the constructor() for Classes,
Insert them as {} objects so order doesn't matter when creating
instances of them
Do this for the Boundary class
class Boundary{ constructor({position}){ this.position = position this.width = 40 this.height = 40 } draw(){ c.fillStyle = 'blue' c.fillRect(this.position.x, this.position.y, this.width,this.height) } }
Put instances of the Boundary class into a
boundaries [].
Use forEach on
draw() method for each new Boundary
const boundaries = [
new Boundary({position : {
x: 40,
y: 40
}
}),
new Boundary({
position: {
x: 80,
y: 40
}
}),
]
boundaries.forEach( el => {
el.draw()
})