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/Errors/Cant_delete below:

TypeError: property "x" is non-configurable and can't be deleted - JavaScript

TypeError: property "x" is non-configurable and can't be deleted Message
TypeError: Calling delete on 'x' is not allowed in strict mode (Edge)
TypeError: property "x" is non-configurable and can't be deleted. (Firefox)
TypeError: Cannot delete property 'x' of #<Object> (Chrome)
Type d'erreur

TypeError in strict mode only.

Quel est le problème ?

Une instruction demande la suppression d'une propriété non-configurable. L'attribut configurable permet de contrôler si la propriété peut être supprimée de l'objet auquel elle est rattachée et si ces attributs (en dehors de writable) peuvent être modifiés.

Cette erreur ne se produit qu'en mode strict. En mode non-strict, l'opération de suppression renverra false.

Exemples

Les propriétés non-configurables ne sont pas très fréquentes mais il est possible d'en créer grâce à Object.defineProperty() ou à Object.freeze().

"use strict";
var obj = Object.freeze({ name: "Elsa", score: 157 });
delete obj.score; // TypeError

("use strict");
var obj = {};
Object.defineProperty(obj, "toto", { value: 2, configurable: false });
delete obj.toto; // TypeError

("use strict");
var frozenArray = Object.freeze([0, 1, 2]);
frozenArray.pop(); // TypeError

Certaines propriétés natives de JavaScript sont non-configurables. Peut-être que le code tente de supprimer une constante mathématique :

"use strict";
delete Math.PI; // TypeError
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