A RetroSearch Logo

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

Search Query:

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

Reflect.has() - JavaScript | MDN

Reflect.has()

Baseline Widely available

Die Reflect.has() statische Methode ist wie der in-Operator, jedoch als Funktion.

Probieren Sie es aus
const object = {
  property1: 42,
};

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

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

console.log(Reflect.has(object, "toString"));
// Expected output: true
Syntax
Reflect.has(target, propertyKey)
Parameter
target

Das Zielobjekt, in dem nach der Eigenschaft gesucht werden soll.

propertyKey

Der Name der zu überprüfenden Eigenschaft.

Rückgabewert

Ein Boolean, das anzeigt, ob das target die Eigenschaft hat oder nicht.

Ausnahmen
TypeError

Wird ausgelöst, wenn target kein Objekt ist.

Beschreibung

Reflect.has() bietet die reflexive Semantik der Überprüfung, ob eine Eigenschaft in einem Objekt vorhanden ist. Das heißt, Reflect.has(target, propertyKey) ist semantisch äquivalent zu:

Reflect.has() ruft die [[HasProperty]]-objektinterne Methode von target auf.

Beispiele Verwendung von Reflect.has()
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

Reflect.has gibt true für alle geerbten Eigenschaften zurück, wie der in-Operator:

const a = { foo: 123 };
const b = { __proto__: a };
const c = { __proto__: b };
// The prototype chain is: c -> b -> a
Reflect.has(c, "foo"); // true
Spezifikationen Browser-Kompatibilität Siehe auch

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