Reflect.has({x: 0}, 'x'); // true
Reflect.has({x: 0}, 'y'); // false
// returns true for properties in the prototype chain
Reflect.has({x: 0}, 'toString');
// Proxy with .has() handler method
obj = new Proxy({}, {
has(t, k) { return k.startsWith('door'); }
});
Reflect.has(obj, 'doorbell'); // true
Reflect.has(obj, 'dormitory'); // false
语法
Reflect.has(target, propertyKey)
参数
target
目标对象.propertyKey
属性名,需要检查目标对象是否存在此属性。
异常
如果目标对象并非 Object 类型,抛出 TypeError
链接:https://cloud.tencent.com/developer/section/1192037