handler.deleteProperty()

La méthode handler.deleteProperty() est une trappe pour l'opérateur delete.

Exemple interactif

Syntaxe

js
var p = new Proxy(cible, {
  deleteProperty: function (cible, propriété) {},
});

Paramètres

Les paramètres suivants sont passés à la méthode deleteProperty. this est lié au gestionnaire.

cible

L'objet cible.

propriété

Le nom ou le symbole (Symbol) de la propriété à supprimer.

Valeur de retour

La méthode deleteProperty() doit renvoyer un booléen qui indique si oui ou non la propriété a été supprimée.

Description

La méthode handler.deleteProperty() est une trappe permettant d'intercepter les opérations de l'opérateur delete.

Interceptions

Cette trappe peut intercepter les opérations suivantes :

Invariants

Si les invarians suivants ne sont pas respectés, le proxy renverra une exception TypeError :

  • Une propriété ne peut pas être supprimée s'il existe une propriété correspondante sur l'objet cible qui est une propriété propre et non-configurable.

Exemples

Dans l'exemple qui suit, on intercepte les opérations de delete.

js
var p = new Proxy(
  {},
  {
    deleteProperty: function (cible, prop) {
      console.log("appelée sur : " + prop);
      return true;
    },
  },
);

delete p.a; // "appelée sur : a"

Spécifications

Specification
ECMAScript Language Specification
# sec-proxy-object-internal-methods-and-internal-slots-delete-p

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi