From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/reflect/has/index.html | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/reflect/has/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/reflect/has/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/has/index.html b/files/zh-cn/web/javascript/reference/global_objects/reflect/has/index.html new file mode 100644 index 0000000000..aaf55532e3 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/has/index.html @@ -0,0 +1,133 @@ +--- +title: Reflect.has() +slug: Web/JavaScript/Reference/Global_Objects/Reflect/has +translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/has +--- +
{{JSRef}}
+ +

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

+ +

句法

+ +
Reflect.has(target, propertyKey)
+
+ +

参数

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

返回值

+ +

一个 {{jsxref("Boolean")}} 类型的对象指示是否存在此属性。

+ +

异常

+ +

如果目标对象并非{{jsxref("Object")}} 类型,抛出{{jsxref("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
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-reflect.has', 'Reflect.has')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-reflect.has', 'Reflect.has')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support49{{CompatGeckoDesktop(42)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile(42)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

相关连接

+ + -- cgit v1.2.3-54-g00ecf