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 --- .../proxy/handler/construct/index.html | 137 --------------------- 1 file changed, 137 deletions(-) delete mode 100644 files/fr/web/javascript/reference/objets_globaux/proxy/handler/construct/index.html (limited to 'files/fr/web/javascript/reference/objets_globaux/proxy/handler/construct') diff --git a/files/fr/web/javascript/reference/objets_globaux/proxy/handler/construct/index.html b/files/fr/web/javascript/reference/objets_globaux/proxy/handler/construct/index.html deleted file mode 100644 index 90eb5f0105..0000000000 --- a/files/fr/web/javascript/reference/objets_globaux/proxy/handler/construct/index.html +++ /dev/null @@ -1,137 +0,0 @@ ---- -title: handler.construct() -slug: Web/JavaScript/Reference/Objets_globaux/Proxy/handler/construct -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Proxy - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/construct ---- -
{{JSRef}}
- -

La méthode handler.construct() est une trappe pour l'opérateur {{jsxref("Opérateurs/L_opérateur_new", "new")}}. Afin que l'opération new puisse être valide sur le proxy correspondant, la cible utilisée doit avoir une méthode interne [[Construct]] (autrement dit, l'instruction new cible doit être valide).

- -
{{EmbedInteractiveExample("pages/js/proxyhandler-construct.html", "taller")}}
- - - -

Syntaxe

- -
var p = new Proxy(cible, {
-  construct: function(cible, listeArguments, newTarget) {
-  }
-});
-
- -

Paramètres

- -

Les paramètres suivants sont passés à la méthode constructthis est ici lié au gestionnaire (handler).

- -
-
cible
-
L'objet cible.
-
listeArguments
-
La liste des arguments passés au constructeur.
-
newTarget
-
Le constructeur originellement appelé.
-
- -

Valeur de retour

- -

La méthode construct doit renvoyer un objet.

- -

Description

- -

La méthode handler.construct() est une trappe pour l'opérateur {{jsxref("Opérateurs/L_opérateur_new", "new")}}.

- -

Interceptions

- -

Ce trappe intercepte les opérations suivantes :

- - - -

Invariants

- -

Si les invariants suivants ne sont pas respectés, le proxy renverra une exception {{jsxref("TypeError")}} :

- - - -

Exemples

- -

Dans l'exemple qui suit, on piège l'opérateur {{jsxref("Opérateurs/L_opérateur_new", "new")}}.

- -
var p = new Proxy(function() {}, {
-  construct: function(target, argumentsList) {
-    console.log("called: " + argumentsList.join(", "));
-    return { value: argumentsList[0] * 10 };
-  }
-});
-
-console.log(new p(1).value); // "appel sur : 1"
-                             // 10
-
- -

Dans cette version, on ne respecte pas la contrainte d'invariance :

- -
var p = new Proxy(function() {}, {
-  construct: function(target, argumentsList) {
-    return 1;
-  }
-});
-
-new p(); // Une exception TypeError est levée
-
- -

Dans le code qui suit, le proxy n'est pas correctement initialisé. La cible du proxy doit être un constructeur valide qui puisse être utilisé avec new.

- -
var p = new Proxy({}, {
-  construct: function(target, argumentsList, newTarget){
-    return {};
-  }
-});
-
-new p(); // TypeError: p is not a constructor
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget', '[[Construct]]')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget', '[[Construct]]')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- - - -

{{Compat("javascript.builtins.Proxy.handler.construct")}}

- -

Voir aussi

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