From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/referenceerror/index.html | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/referenceerror/index.html (limited to 'files/fr/web/javascript/reference/global_objects/referenceerror') diff --git a/files/fr/web/javascript/reference/global_objects/referenceerror/index.html b/files/fr/web/javascript/reference/global_objects/referenceerror/index.html new file mode 100644 index 0000000000..497cd92dd5 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/referenceerror/index.html @@ -0,0 +1,131 @@ +--- +title: ReferenceError +slug: Web/JavaScript/Reference/Objets_globaux/ReferenceError +tags: + - Error + - JavaScript + - Object + - Reference + - ReferenceError +translation_of: Web/JavaScript/Reference/Global_Objects/ReferenceError +--- +
{{JSRef}}
+ +

L'objet ReferenceError représente une erreur qui se produit lorsqu'il est fait référence à une variable qui n'existe pas.

+ +

Syntaxe

+ +
new ReferenceError([message[, nomFichier[, numLigne]]])
+ +

Paramètres

+ +
+
message
+
Paramètre optionnel. Une description de l'erreur, lisible par un être humain.
+
nomFichier {{Non-standard_inline}}
+
Paramètre optionnel. Le nom du fichier qui contient le code à l'origine de l'exception.
+
numLigne {{Non-standard_inline}}
+
Paramètre optionnel. Le numéro de ligne dans le fichier qui contient le code à l'origine de l'exception.
+
+ +

Description

+ +

Une exception ReferenceError est lancée quand on tente de faire référence à une variable qui n'a pas été déclarée.

+ +

Propriétés

+ +
+
{{jsxref("ReferenceError.prototype")}}
+
Cette propriété permet d'ajouter des propriétés à un objet ReferenceError.
+
+ +

Méthodes

+ +

L'objet global ReferenceError ne contient aucune méthode qui lui soit propre. En revanche, il hérite de certaines méthodes via l'héritage et sa chaîne de prototypes.

+ +

Instances de ReferenceError

+ +

Propriétés

+ +
{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/ReferenceError/prototype','Properties')}}
+ +

Méthodes

+ +
{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/ReferenceError/prototype','M.C3.A9thodes')}}
+ +

Exemples

+ +

Intercepter une exception ReferenceError

+ +
try {
+  var a = variableNonDéfinie;
+} catch (e) {
+  console.log(e instanceof ReferenceError); // true
+  console.log(e.message);                   // "variableNonDéfinie is not defined"
+  console.log(e.name);                      // "ReferenceError"
+  console.log(e.fileName);                  // "Scratchpad/1"
+  console.log(e.lineNumber);                // 2
+  console.log(e.columnNumber);              // 6
+  console.log(e.stack);                     // "@Scratchpad/2:2:7\n"
+}
+ +

Créer une exception ReferenceError

+ +
try {
+  throw new ReferenceError('Bonjour', 'unFichier.js', 10);
+} catch (e) {
+  console.log(e instanceof ReferenceError); // true
+  console.log(e.message);                   // "Bonjour"
+  console.log(e.name);                      // "ReferenceError"
+  console.log(e.fileName);                  // "unFichier.js"
+  console.log(e.lineNumber);                // 10
+  console.log(e.columnNumber);              // 0
+  console.log(e.stack);                     // "@Scratchpad/2:2:9\n"
+}
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationStatutCommentaires
{{SpecName('ES3')}}{{Spec2('ES3')}}Définition initiale.
{{SpecName('ES5.1', '#sec-15.11.6.3', 'ReferenceError')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-referenceerror', 'ReferenceError')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-referenceerror', 'ReferenceError')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +
+ + +

{{Compat("javascript.builtins.ReferenceError")}}

+
+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf