Overview

How it works

Table Of Contents

Code

//ES6 Reflect API - Reflect.construct(), apply(), and prototype interaction

class Pet {
  constructor() {
    this.name = "Broccoli";
  }
}

let pet = new Pet();

Pet.prototype.age = 4;

let proto = {
  age : 8,
  eat() {
    console.log('Chewing');
  }
}

Reflect.setPrototypeOf(pet, proto);

//Apply
Reflect.apply(pet.eat, null, [])
console.log(Reflect.getPrototypeOf(pet))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Last Updated: 8/13/2019, 6:55:26 PM