[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has [Back]  [Original]

Reflect.has() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Reflect.has()

Baseline

20169

Reflect.has() in

const object = {
  property1: 42,
};

console.log(Reflect.has(object, "property1"));
// : true

console.log(Reflect.has(object, "property2"));
// : false

console.log(Reflect.has(object, "toString"));
// : true

js
Reflect.has(target, propertyKey)

target

propertyKey

(Boolean)

TypeError

target

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

js
propertyKey in target;

Reflect.has() target [[HasProperty]]

Reflect.has()

js
Reflect.has({ x: 0 }, "x"); // true
Reflect.has({ x: 0 }, "y"); // false

// true 
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 true in

js
const a = { foo: 123 };
const b = { __proto__: a };
const c = { __proto__: b };
// The prototype chain is: c -> b -> a
Reflect.has(c, "foo"); // true

ECMAScript 2027 LanguageSpecification
# sec-reflect.has


Web Proxy Viewer  |  New URL  |  Original Page