Print bounding box in the terminal Right now I am finding ways to write better code in javascript and I see many coding styles used by different authors but right now I am thinking to write code which adheres to the object oriented paradigm better suited for this type of language.

Code

// Terminal

'use strict';

class Terminal {
  constructor() {
    this.cols = process.stdout.columns || 80
    this.rows = process.stdout.rows || 60
  }

  width() {
    return this.cols
  }

  height() {
    return this.rows
  }
}

module.exports = Terminal


// Box

'use strict';

const Terminal = require('./terminal')

class Box {
  constructor(opts) {
    let terminal = new Terminal()
    const defaults = {
      w: terminal.width(),
      h: terminal.height(),
      t: '══',
      tr: '╗',
      r: '║',
      br: '╝',
      b: '══',
      bl: '╚',
      l: '║',
      tl: '╔',
      fill: '░░'
    }
    this.settings = Object.assign(defaults, opts)
  }

  toString() {
    const res = [];
    const { t, tr, r, br, b, bl, l, tl } = this.settings
    const { w , h } = this.settings
    // Filling row wise
    for (let i = 0; i &lt; h; i++) {
      for (let j = 0; j &lt; w; j++) {
        if (i === 0 &amp;&amp; j === 0) {
          res.push(tl)
        }
        else if (i === 0 &amp;&amp; j === w - 1) {
          res.push(tr)
        }
        else if ((i === h - 1) &amp;&amp; (j === w - 1)) {
          res.push(br)
        }
        else if ((i === h - 1) &amp;&amp; j === 0) {
          res.push(bl)
        }
        else if (this.isFirstRow(i) || this.isLastRow(i)) {
          res.push(t)
        }
        else if (this.isFirstCol(j) || this.isLastCol(j)) {
          res.push(l)
        }
        else {
          const { fill } = this.settings
          res.push(fill)
        }
      }
      res.push('\n')
    }
    return res.join('')
  }

  isFirstRow(row) {
    return row === 0
  }

  isLastRow(row) {
    const { h } = this.settings
    return row === h - 1
  }

  isFirstCol(col) {
    return col === 0
  }

  isLastCol(col) {
    const { w } = this.settings
    return col === w - 1
  }
}

class TopRight {
  constructor() {
    this.symbol = '╗'
  }

  toString() {
    return this.symbol
  }
}

class BottomRight {
  constructor() {
    this.symbol = '╝'
  }

  toString() {
    return this.symbol
  }
}

class BottomLeft {
  constructor() {
    this.symbol = '╚'
  }

  toString() {
    return this.symbol
  }
}

class TopLeft {
  constructor() {
    this.symbol = '╔'
  }

  toString() {
    return this.symbol
  }
}

module.exports = Box

// O/P
/*
&gt; const B = require('./box')
&gt; console.log(new B({w: 8, h: 8, fillSymbol: '||'}).toString())
╔════════════╗
║░░░░░░░░░░░░║
║░░░░░░░░░░░░║
║░░░░░░░░░░░░║
║░░░░░░░░░░░░║
║░░░░░░░░░░░░║
║░░░░░░░░░░░░║
╚════════════╝
*/


I would like to know how to improve the above code to make better use of prototypal inheritance and delegation which is widely advocated in javascript world.

Note

I thought to use classes for printing symbols but I see that they make code more bloated. I left them there hear opinion of others.
This can be order of magnitudes simpler.  You want a function that takes a width, height, and optional fill character, and returns a string (your box).

Try this:

function box(w, h, fill='░░') {
  const top    = '╔' + '══'.repeat(w-2) + '╗\n' 
  const row    = '║' + fill.repeat(w-2) + '║\n'
  const bottom = '╚' + '══'.repeat(w-2) + '╝'
  return top + row.repeat(h-2) + bottom
}