01-01 - Constructor Parameter as {} object

01/01-01/01-01-js.html

01

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)

    }
}

02

Put instances of the Boundary class into a boundaries []. Use forEach on

boundaries
and evoke the 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()
})