标签:
let Class = class {};
Reflect.construct(Class) instanceof Class // true
let obj = {x: 23};
Reflect.get(obj, ‘x‘) // 23
Reflect.has(obj, ‘x‘) // true
执行函数:
let fn = () => {return 42;};
Reflect.apply(fn) // 42
指定context:
class FourtyTwo {
constructor() { this.value = 42}
fn() {return this.value}
}
let instance = new FourtyTwo();
const fourtyTwo = Reflect.apply(instance.fn, instance); // 42
以数组形式传递参数:
let emptyArrayWithFiveElements = Reflect.apply(Array, [], [5]); // new Array(5)
emptyArrayWithFiveElements.fill(42) // [42, 42, 42, 42, 42]
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;
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)
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
标签:
原文地址:http://www.cnblogs.com/benben77/p/4771407.html