Reflect: Basics:
Let class = class {};
Reflect.construct (Class) Instanceof class//True
Let obj = {x:23};
Reflect.get (obj, ' x ')//23
Reflect.has (obj, ' x ')//True
Apply
Execute function:
LET fn = () = {return 42;};
Reflect.apply (FN)//42
Specify context:
Class Fourtytwo {
Constructor () {this.value = 42}
fn () {return this.value}
}
Let instance = new Fourtytwo ();
Const FOURTYTWO = reflect.apply (Instance.fn, instance); 42
To pass parameters as an array:
Let emptyarraywithfiveelements = reflect.apply (Array, [], [5]); New Array (5)
Emptyarraywithfiveelements.fill (42)//[42, 42, 42, 42, 42]
Getprototypeof:
Const Viaobject = object.getprototypeof ({});
Const Viareflect = reflect.getprototypeof ({});
Reflect.getprototypeof ()//TypeError
Const ASET = new Set ();
Reflect.getprototypeof (ASet)//Set.prototype
Let arr = [];
Reflect.getprototypeof (arr)//Array.prototype;
Construct
Let afunction = () = {};
Reflect.construct (afunction)
Const ACLASS = class {};
Reflect.construct (AClass)
Let Arraylike = {get Length () {return 2}};
Reflect.construct (AClass, Arraylike)
Let Realarray = [];
Reflect.construct (AClass, Realarray)
DefineProperty:
Let obj = {};
Reflect.defineproperty (obj, ' prop ', {}); ' Prop ' in obj
Let obj = {};
Const SYM = symbol.for (' prop ');
Reflect.defineproperty (obj, sym, {}); Sym in obj
Let obj = {};
var success = Reflect.defineproperty (obj, ' prop ', {value: ' value '}); Obj.prop: ' Value ', success:true
Learn some ES6: Reflection