静态方法 Reflect
.has()
作用与 in
操作符 相同。
Reflect.has(target, propertyKey)
target
propertyKey
一个 Boolean
类型的对象指示是否存在此属性。
如果目标对象并非Object
类型,抛出TypeError
。
Reflect.has
用于检查一个对象是否拥有某个属性, 相当于in
操作符 。
Reflect.has()
Reflect.has({x: 0}, "x"); // true
Reflect.has({x: 0}, "y"); // false
// 如果该属性存在于原型链中,返回true
Reflect.has({x: 0}, "toString");
// Proxy 对象的 .has() 句柄方法
obj = new Proxy({}, {
has(t, k) { return k.startsWith("door"); }
});
Reflect.has(obj, "doorbell"); // true
Reflect.has(obj, "dormitory"); // false
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Reflect.has |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) Reflect.has |
Draft |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 49 | 42 (42) | 未实现 | 未实现 | 未实现 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 未实现 | 未实现 | 42.0 (42) | 未实现 | 未实现 | 未实现 |