Example One - Creating a object with reflect (required arguments)
//ES6 Reflect API - Creating objects - the Optional third argument
class Daughter {
constructor(name) {
this.name = name;
}
}
//Construct takes up to three arguments
// First Argument - constructor function to use for the class
// Second Argument - array which specifies what to pass through the constructor
// Third Argument (optional) - used to override the prototype
let daughter = Reflect.construct(Daughter, ['Annabelle']);
console.log(daughter)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Example Two - Creating a object with reflect (optional argument)
//ES6 Reflect API - Creating objects - the Optional third argument
class Daughter {
constructor(name) {
this.name = name;
}
}
//Construct function we will use to overwrite the Daughter prototoype
function OverObj() {
this.age = 2;
}
let daughter = Reflect.construct(Daughter, ['Annabelle'], OverObj);
console.log(daughter)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15