首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Reflect.has

静态方法?Reflect.has()作用与?in操作符?相同。

语法

代码语言:javascript
复制
Reflect.has(target, propertyKey)

参数

target目标对象.propertyKey属性名,需要检查目标对象是否存在此属性。

返回值

一个Boolean类型的对象指示是否存在此属性。

异常

如果目标对象并非Object?类型,抛出TypeError

描述

Reflect.has用于检查一个对象是否拥有某个属性, 相当于in操作符?。

示例

使用Reflect.has()

代码语言:javascript
复制
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

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Reflect.has' in that specification.

Standard

Initial definition.

ECMAScript Latest Draft (ECMA-262)The definition of 'Reflect.has' in that specification.

Living Standard

?

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

49

(Yes)

42 (42)

No support

(Yes)

10

Feature

Android

Chrome for Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

49

(Yes)

42.0 (42)

No support

No support

10

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com