Create a plain Object vs Create an Area instance

Edit on GitHub

Creating of a plaing Object vs instantiating a custom “class”

Setup

class Area {

    constructor(start, end) {
        this._start = start
        this._end = end
    }

    includes(area, position) {
    }

    isVisible(area, leftTopPosition) {
    }

    positionIsOnTheEdge(area, geometry, edgeType) {
    }

    isSubArea(area, subArea) {
    }

    normalizeArea(area) {
    }

    positions(area) {
    }
}

Tests

  • Create a plain Object

    const area = {
      start: { row: 0, col: 0 },
      end: { row: 2, col: 2 }
    }
  • Create an Area instance

    const area = new Area({ row: 0, col: 0 }, { row: 2, col: 2 })