A RetroSearch Logo

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

Search Query:

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

Reflect.has() - JavaScript | MDN

Reflect.has()

Baseline Widely available

La méthode statique Reflect.has() fonctionne comme l'opérateur in mais sous forme d'une fonction.

Exemple interactif
const object1 = {
  property1: 42,
};

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

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

console.log(Reflect.has(object1, "toString"));
// Expected output: true
Syntaxe
Reflect.has(cible, cléPropriété);
Paramètres
cible

L'objet cible dont on souhaite savoir s'il contient la propriété donnée.

cléPropriété

Le nom de la propriété dont on souhaite vérifier la présence.

Valeur de retour

Un booléen qui indique si la propriété recherchée est présente sur l'objet cible.

Exceptions

Une erreur TypeError si cible n'est pas un Object.

Description

La méthode Reflect.has vous permet de vérifier si une propriété est présente sur un objet. C'est une fonction qui agit comme l'opérateur in.

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

// renvoie true pour les propriétés présentes
// grâce à la chaîne de prototypes
Reflect.has({ x: 0 }, "toString");

// Proxy avec la méthode .has()
obj = new Proxy(
  {},
  {
    has(t, k) {
      return k.startsWith("bou");
    },
  },
);
Reflect.has(obj, "bouchon"); // true
Reflect.has(obj, "bonbon"); // false
Spécifications Compatibilité des navigateurs Voir aussi

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