A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has below:

Reflect.has() - JavaScript | MDN

Reflect.has()

Baseline Widely available

静态方法 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
规范 浏览器兼容性 相关连接

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4