Through a technique called 'subclassing' In ES6 we can overide, and extend the built in javascript objects such as arrays etc.

Code

Extending Built-in Objects - Subclassing


//Extending the built in Javascript Array Object
class ConvertableArray extends Array {
  convert() {
    let returnArray = [];
    this.forEach(value => returnArray.push('Converted!' + value));
    return returnArray;
  }
}

let numberArray = new ConvertableArray();
numberArray.push(1);
numberArray.push(2);
numberArray.push(3);

console.log(numberArray.convert());


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Resources

[List of extandable built in objects] - "https://kangax.github.io/compat-table/es6/"

Last Updated: 8/13/2019, 6:55:26 PM