diff --git a/files/fr/web/javascript/reference/global_objects/string/sub/index.md b/files/fr/web/javascript/reference/global_objects/string/sub/index.md index 13776e8b62cd36..0a9fe7ec388335 100644 --- a/files/fr/web/javascript/reference/global_objects/string/sub/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/sub/index.md @@ -11,7 +11,7 @@ La méthode **`sub()`** crée un élément HTML {{HTMLElement("sub")}} qui entra ## Syntaxe ```js -str.sub() +str.sub(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/string/substr/index.md b/files/fr/web/javascript/reference/global_objects/string/substr/index.md index cab2bb413039f0..ac989da252aa07 100644 --- a/files/fr/web/javascript/reference/global_objects/string/substr/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/substr/index.md @@ -50,16 +50,16 @@ Pour `début` comme pour `longueur`, NaN est traité comme 0. ## Exemples ```js -var uneChaine = 'Mozilla'; - -console.log(uneChaine.substr(0, 1)); // 'M' -console.log(uneChaine.substr(1, 0)); // '' -console.log(uneChaine.substr(-1, 1)); // 'a' -console.log(uneChaine.substr(1, -1)); // '' -console.log(uneChaine.substr(-3)); // 'lla' -console.log(uneChaine.substr(1)); // 'ozilla' +var uneChaine = "Mozilla"; + +console.log(uneChaine.substr(0, 1)); // 'M' +console.log(uneChaine.substr(1, 0)); // '' +console.log(uneChaine.substr(-1, 1)); // 'a' +console.log(uneChaine.substr(1, -1)); // '' +console.log(uneChaine.substr(-3)); // 'lla' +console.log(uneChaine.substr(1)); // 'ozilla' console.log(uneChaine.substr(-20, 2)); // 'Mo' -console.log(uneChaine.substr(20, 2)); // '' +console.log(uneChaine.substr(20, 2)); // '' ``` ## Prothèse d'émulation (_polyfill_) @@ -68,23 +68,25 @@ JScript de Microsoft ne supporte pas les valeurs négatives pour l'indice de dé ```js // N'appliquer que lorsque la fonction est incomplète -if ('ab'.substr(-1) != 'b') { +if ("ab".substr(-1) != "b") { /** * Obtenir la sous-chaîne d'une chaîne * @param {entier} début où démarrer la sous-chaîne * @param {entier} longueur combien de caractères à retourner * @return {chaîne} */ - String.prototype.substr = function(substr) { - return function(début, longueur) { + String.prototype.substr = (function (substr) { + return function (début, longueur) { // Appel de la méthode originale - return substr.call(this, + return substr.call( + this, // Si on a un début négatif, calculer combien il vaut à partir du début de la chaîne // Ajuster le paramètre pour une valeur négative début < 0 ? this.length + début : début, - longueur) - } - }(String.prototype.substr); + longueur, + ); + }; + })(String.prototype.substr); } ``` diff --git a/files/fr/web/javascript/reference/global_objects/string/substring/index.md b/files/fr/web/javascript/reference/global_objects/string/substring/index.md index 8225320be57d88..057be67f544df6 100644 --- a/files/fr/web/javascript/reference/global_objects/string/substring/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/substring/index.md @@ -48,20 +48,20 @@ Les exemples suivants utilisent la méthode `substring()` pour extraire et affic var uneChaîne = "Mozilla"; // Affiche "Moz" -console.log(uneChaîne.substring(0,3)); -console.log(uneChaîne.substring(3,0)); +console.log(uneChaîne.substring(0, 3)); +console.log(uneChaîne.substring(3, 0)); // Affiche "lla" -console.log(uneChaîne.substring(4,7)); +console.log(uneChaîne.substring(4, 7)); console.log(uneChaîne.substring(4)); -console.log(uneChaîne.substring(7,4)); +console.log(uneChaîne.substring(7, 4)); // Affiche "Mozill" -console.log(uneChaîne.substring(0,6)); +console.log(uneChaîne.substring(0, 6)); // Affiche "Mozilla" -console.log(uneChaîne.substring(0,7)); -console.log(uneChaîne.substring(0,10)); +console.log(uneChaîne.substring(0, 7)); +console.log(uneChaîne.substring(0, 10)); ``` ### Remplacer une sous-chaîne dans une chaîne @@ -70,10 +70,13 @@ L'exemple suivant remplace une partie d'une chaine. Elle remplace à la fois les ```js function replaceString(oldS, newS, fullS) { -// On remplace oldS avec newS dans fullS + // On remplace oldS avec newS dans fullS for (var i = 0; i < fullS.length; i++) { if (fullS.substring(i, i + oldS.length) == oldS) { - fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length, fullS.length); + fullS = + fullS.substring(0, i) + + newS + + fullS.substring(i + oldS.length, fullS.length); } } return fullS; @@ -85,7 +88,7 @@ replaceString("World", "Web", "Brave New World"); Attention : ceci peut résulter en une boucle infinie si `oldS` est elle-même une sous-chaine de `newS` — par exemple, si on essaie de remplacer "World" par "OtherWorld". Une meilleure solution serait de remplacer les chaines de cette manière : ```js -function replaceString(oldS, newS,fullS){ +function replaceString(oldS, newS, fullS) { return fullS.split(oldS).join(newS); } ``` @@ -100,8 +103,8 @@ Les arguments de la méthode `substring()` représentent les indices de début e ```js var texte = "Mozilla"; -console.log(texte.substring(2,5)); // => "zil" -console.log(texte.substr(2,3)); // => "zil" +console.log(texte.substring(2, 5)); // => "zil" +console.log(texte.substr(2, 3)); // => "zil" ``` ### Différences entre `substring()` et `slice()` @@ -111,9 +114,9 @@ Les méthodes `substring()` et {{jsxref("String.slice", "slice()")}} sont très La méthode `substring()` échangera les deux arguments si `indiceA` est supérieur à `indiceB` et renverra donc une chaîne de caractères. La méthode {{jsxref("String.slice", "slice()")}} n'échange pas les arguments et renvoie donc une chaîne vide si le premier est supérieur au second : ```js -var text = 'Mozilla'; +var text = "Mozilla"; console.log(text.substring(5, 2)); // => "zil" -console.log(text.slice(5, 2)); // => "" +console.log(text.slice(5, 2)); // => "" ``` Si l'un ou l'autre des arguments sont négatifs ou valent `NaN`, la méthode `substring()` les traitera comme s'ils valaient `0`. diff --git a/files/fr/web/javascript/reference/global_objects/string/sup/index.md b/files/fr/web/javascript/reference/global_objects/string/sup/index.md index 9c2ca878f924ae..b5429282a91cc9 100644 --- a/files/fr/web/javascript/reference/global_objects/string/sup/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/sup/index.md @@ -11,7 +11,7 @@ La méthode **`sup()`** crée un élément HTML {{HTMLElement("sup")}} qui entra ## Syntaxe ```js -str.sup() +str.sup(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/string/tolocaleuppercase/index.md b/files/fr/web/javascript/reference/global_objects/string/tolocaleuppercase/index.md index 75a502ae3eab14..2acc0365396539 100644 --- a/files/fr/web/javascript/reference/global_objects/string/tolocaleuppercase/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/tolocaleuppercase/index.md @@ -43,8 +43,8 @@ On notera également que la conversion ne repose pas sur une correspondance un ## Exemples ```js -"alphabet".toLocaleUpperCase(); // "ALPHABET" -'Gesäß'.toLocaleUpperCase(); // 'GESÄSS' +"alphabet".toLocaleUpperCase(); // "ALPHABET" +"Gesäß".toLocaleUpperCase(); // 'GESÄSS' "i\u0307".toLocaleUpperCase("lt-LT"); // "I" ``` diff --git a/files/fr/web/javascript/reference/global_objects/string/tolowercase/index.md b/files/fr/web/javascript/reference/global_objects/string/tolowercase/index.md index 258fd67f16a8ff..bdcf04d8cb072c 100644 --- a/files/fr/web/javascript/reference/global_objects/string/tolowercase/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/tolowercase/index.md @@ -13,7 +13,7 @@ La méthode **`toLowerCase()`** retourne la chaîne de caractères courante en m ## Syntaxe ```js -str.toLowerCase() +str.toLowerCase(); ``` ### Valeur de retour @@ -27,7 +27,7 @@ La méthode `toLowerCase()` renvoie la valeur de la chaîne convertie en minuscu ## Exemples ```js -console.log( "ALPHABET".toLowerCase() ); // "alphabet" +console.log("ALPHABET".toLowerCase()); // "alphabet" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/string/tostring/index.md b/files/fr/web/javascript/reference/global_objects/string/tostring/index.md index 606fc0b2b6e41c..be500553bacd74 100644 --- a/files/fr/web/javascript/reference/global_objects/string/tostring/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/tostring/index.md @@ -13,7 +13,7 @@ La méthode **`toString()`** renvoie une chaine de caractères représentant l'o ## Syntaxe ```js -str.toString() +str.toString(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/string/touppercase/index.md b/files/fr/web/javascript/reference/global_objects/string/touppercase/index.md index 991ccf03d51be4..4d9cfd5619658b 100644 --- a/files/fr/web/javascript/reference/global_objects/string/touppercase/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/touppercase/index.md @@ -13,7 +13,7 @@ La méthode **`toUpperCase()`** retourne la valeur de la chaîne courante, conve ## Syntaxe ```js -str.toUpperCase() +str.toUpperCase(); ``` ### Valeur de retour @@ -34,7 +34,7 @@ La méthode `toUpperCase()` retourne la valeur de la chaîne convertie en majusc ### Utiliser `toUpperCase()` ```js -console.log( "alphabet".toUpperCase() ); // "ALPHABET" +console.log("alphabet".toUpperCase()); // "ALPHABET" ``` ### Convertir une valeur `this` en chaîne de caractères @@ -43,9 +43,9 @@ Cette peut être utilisée pour convertir une valeur qui n'est pas une chaîne d ```js var obj = { - toString: function toString(){ - return 'abcdef'; - } + toString: function toString() { + return "abcdef"; + }, }; var a = String.prototype.toUpperCase.call(obj); var b = String.prototype.toUpperCase.call(true); diff --git a/files/fr/web/javascript/reference/global_objects/string/trim/index.md b/files/fr/web/javascript/reference/global_objects/string/trim/index.md index 81e055413861ae..b776e33371bf7e 100644 --- a/files/fr/web/javascript/reference/global_objects/string/trim/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/trim/index.md @@ -13,7 +13,7 @@ La méthode **`trim()`** permet de retirer les blancs en début et fin de chaîn ## Syntaxe ```js -str.trim() +str.trim(); ``` ### Valeur de retour @@ -29,12 +29,12 @@ La méthode `trim()` renvoie la chaîne sans blanc au début et à la fin. La m L'exemple qui suit affiche la chaîne `'toto'` : ```js -var chaîneOriginale = ' toto '; +var chaîneOriginale = " toto "; console.log(chaîneOriginale.trim()); // 'toto' // Un autre exemple de .trim() qui enlève les espaces juste d'un côté -var chaîneOriginale = 'toto '; +var chaîneOriginale = "toto "; console.log(chaîneOriginale.trim()); // 'toto' ``` @@ -45,7 +45,7 @@ Si l'environnement utilisé ne possède pas cette méthode, il est possible de l ```js if (!String.prototype.trim) { String.prototype.trim = function () { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); }; } ``` diff --git a/files/fr/web/javascript/reference/global_objects/string/trimend/index.md b/files/fr/web/javascript/reference/global_objects/string/trimend/index.md index cd9a69a4d47543..66796b9434175a 100644 --- a/files/fr/web/javascript/reference/global_objects/string/trimend/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/trimend/index.md @@ -35,7 +35,7 @@ String.prototype.trimRight.name === "trimEnd"; ## Exemples -L'exemple qui suit illustre comment afficher la chaîne " toto": +L'exemple qui suit illustre comment afficher la chaîne " toto": ```js var str = " toto "; @@ -44,7 +44,7 @@ console.log(str.length); // 9 str = str.trimEnd(); console.log(str.length); // 7 -console.log(str); // " toto" +console.log(str); // " toto" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/string/trimstart/index.md b/files/fr/web/javascript/reference/global_objects/string/trimstart/index.md index eaa6026a44b293..da5753ec3d1956 100644 --- a/files/fr/web/javascript/reference/global_objects/string/trimstart/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/trimstart/index.md @@ -44,7 +44,7 @@ console.log(str.length); // 8 str = str.trimStart(); console.log(str.length); // 5 -console.log(str); // "toto " +console.log(str); // "toto " ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/string/valueof/index.md b/files/fr/web/javascript/reference/global_objects/string/valueof/index.md index bdf350289cbc82..e52e45217178bc 100644 --- a/files/fr/web/javascript/reference/global_objects/string/valueof/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/valueof/index.md @@ -13,7 +13,7 @@ La méthode **`valueOf()`** renvoie la valeur primitive de l'objet {{jsxref("Str ## Syntaxe ```js -str.valueOf() +str.valueOf(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md index 1aab021694d49a..23ab566588d8d7 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md @@ -22,20 +22,20 @@ Il est possible de définir son propre itérable en définissant la propriété ```js const myAsyncIterable = new Object(); -myAsyncIterable[Symbol.asyncIterator] = async function*() { - yield "coucou"; - yield "l'itération"; - yield "asynchrone !"; +myAsyncIterable[Symbol.asyncIterator] = async function* () { + yield "coucou"; + yield "l'itération"; + yield "asynchrone !"; }; (async () => { - for await (const x of myAsyncIterable) { - console.log(x); - // expected output: - // "coucou" - // "l'itération" - // "asynchrone !" - } + for await (const x of myAsyncIterable) { + console.log(x); + // expected output: + // "coucou" + // "l'itération" + // "asynchrone !" + } })(); ``` diff --git a/files/fr/web/javascript/reference/global_objects/symbol/description/index.md b/files/fr/web/javascript/reference/global_objects/symbol/description/index.md index b983ed006a8ab5..0035def4774874 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/description/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/description/index.md @@ -13,9 +13,9 @@ La propriété en lecture seule **`description`** est une chaîne de caractères ## Syntaxe ```js -Symbol('maDescription').description; +Symbol("maDescription").description; Symbol.iterator.description; -Symbol.for('toto').description; +Symbol.for("toto").description; ``` ## Description @@ -25,18 +25,18 @@ Les objets {{jsxref("Symbol")}} peuvent être créés avec une description facul ## Exemples ```js -Symbol('desc').toString(); // "Symbol(desc)" -Symbol('desc').description; // "desc" -Symbol('').description; // "" -Symbol().description; // undefined +Symbol("desc").toString(); // "Symbol(desc)" +Symbol("desc").description; // "desc" +Symbol("").description; // "" +Symbol().description; // undefined // symboles connus -Symbol.iterator.toString(); // "Symbol(Symbol.iterator)" +Symbol.iterator.toString(); // "Symbol(Symbol.iterator)" Symbol.iterator.description; // "Symbol.iterator" // symboles globaux -Symbol.for('toto').toString(); // "Symbol(toto)" -Symbol.for('toto').description; // "toto" +Symbol.for("toto").toString(); // "Symbol(toto)" +Symbol.for("toto").description; // "toto" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/symbol/index.md b/files/fr/web/javascript/reference/global_objects/symbol/index.md index 6b1eed66f7a770..43bbdb5c6f5922 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/index.md @@ -16,14 +16,14 @@ Pour créer une nouvelle valeur primitive symbole, il suffit d'appeler `Symbol() ```js let sym1 = Symbol(); -let sym2 = Symbol('toto'); -let sym3 = Symbol('toto'); +let sym2 = Symbol("toto"); +let sym3 = Symbol("toto"); ``` Le fragment de code ci-dessus permet de créer trois nouveaux symboles. On notera que l'instruction `Symbol('toto')` ne convertit pas la chaîne `'toto'` en un symbole. On crée bien un nouveau symbole pour chaque instruction ci-avant. ```js -Symbol('toto') === Symbol('toto'); // false +Symbol("toto") === Symbol("toto"); // false ``` La syntaxe suivante, utilisant l'opérateur [`new`](/fr/docs/Web/JavaScript/Reference/Operators/new), entraînera une exception [`TypeError`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypeError) : @@ -37,10 +37,10 @@ Cela est fait pour empêcher d'écrire une enveloppe (wrapper) Si on souhaite obtenir un object contenant un symbole, on pourra toujours utiliser la fonction `Object()` : ```js -let sym = Symbol('toto'); -typeof sym; // "symbol" +let sym = Symbol("toto"); +typeof sym; // "symbol" let symObj = Object(sym); -typeof symObj; // "object" +typeof symObj; // "object" ``` ### Symboles partagés et registre global des symboles @@ -113,9 +113,9 @@ La méthode [`Object.getOwnPropertySymbols()`](/fr/docs/Web/JavaScript/Reference L'opérateur [`typeof`](/fr/docs/Web/JavaScript/Reference/Operators/typeof) permet d'identifier des symboles : ```js -typeof Symbol() === 'symbol' -typeof Symbol('toto') === 'symbol' -typeof Symbol.iterator === 'symbol' +typeof Symbol() === "symbol"; +typeof Symbol("toto") === "symbol"; +typeof Symbol.iterator === "symbol"; ``` ### Les symboles et les conversions @@ -134,10 +134,10 @@ Les symboles ne peuvent pas être énumérés dans les boucles [`for…in`](/fr/ ```js let obj = {}; -obj[Symbol('a')] = 'a'; -obj[Symbol.for('b')] = 'b'; -obj['c'] = 'c'; -obj.d = 'd'; +obj[Symbol("a")] = "a"; +obj[Symbol.for("b")] = "b"; +obj["c"] = "c"; +obj.d = "d"; for (let i in obj) { console.log(i); // affiche "c" et "d" @@ -149,7 +149,7 @@ for (let i in obj) { Les propriétés identifiées par des symboles seront totalement ignorées par `JSON.stringify()` : ```js -JSON.stringify({[Symbol('toto')]: 'toto'}); +JSON.stringify({ [Symbol("toto")]: "toto" }); // '{}' ``` @@ -160,10 +160,10 @@ Pour plus de détails, voir la page [`JSON.stringify()`](/fr/docs/Web/JavaScript Lorsqu'on utilise un objet pour contenir la valeur du symbole et faire référence à une propriété, l'objet sera ramené au symbole d'origine : ```js -let sym = Symbol('toto') -let obj = {[sym]: 1}; -obj[sym]; // 1 -obj[Object(sym)]; // toujours 1 +let sym = Symbol("toto"); +let obj = { [sym]: 1 }; +obj[sym]; // 1 +obj[Object(sym)]; // toujours 1 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md b/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md index cb7c9b327ec222..ba50223d022281 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md @@ -26,8 +26,8 @@ Le symbole `@@isConcatSpreadable` (`Symbol.isConcatSpreadable`) peut être défi Par défaut, {{jsxref("Array.prototype.concat()")}} aplatit les tableaux pour le résultat de la concaténation : ```js -var alpha = ['a', 'b', 'c'], - numérique = [1, 2, 3]; +var alpha = ["a", "b", "c"], + numérique = [1, 2, 3]; var alphaNumérique = alpha.concat(numérique); @@ -38,8 +38,8 @@ console.log(alphaNumérique); En définissant `Symbol.isConcatSpreadable` avec `false`, on peut désactiver le comportement par défaut : ```js -var alpha = ['a', 'b', 'c'], - numérique = [1, 2, 3]; +var alpha = ["a", "b", "c"], + numérique = [1, 2, 3]; numérique[Symbol.isConcatSpreadable] = false; var alphaNumérique = alpha.concat(numérique); @@ -59,8 +59,8 @@ var fauxTableau = { [Symbol.isConcatSpreadable]: true, length: 2, 0: "coucou", - 1: "monde" -} + 1: "monde", +}; x.concat(fauxTableau); // [1, 2, 3, "coucou", "monde"] ``` diff --git a/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md b/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md index 13e65ccf471248..651d89f0383de2 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md @@ -33,13 +33,13 @@ Pour plus d'informations, voir aussi [la page sur les protocoles d'itération](/ Il est possible de construire un itérable de la façon suivante : ```js -var monItérable = {} +var monItérable = {}; monItérable[Symbol.iterator] = function* () { - yield 1; - yield 2; - yield 3; + yield 1; + yield 2; + yield 3; }; -[...monItérable] // [1, 2, 3] +[...monItérable]; // [1, 2, 3] ``` On peut également définir ces itérables via des propriétés calculées dans des déclarations de classe ou dans des littéraux objets : diff --git a/files/fr/web/javascript/reference/global_objects/symbol/match/index.md b/files/fr/web/javascript/reference/global_objects/symbol/match/index.md index c18bcf2e9da2db..6776052c92ce41 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/match/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/match/index.md @@ -34,7 +34,7 @@ Cependant, si `Symbol.match` vaut `false`, cette vérification `isRegExp` indiqu var re = /toto/; re[Symbol.match] = false; "/toto/".startsWith(re); // true -"/truc/".endsWith(re); // false +"/truc/".endsWith(re); // false ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md b/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md index 252cf9cc19d7ca..7f57c25dadc580 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md @@ -15,9 +15,9 @@ Le symbole connu **`Symbol.matchAll`** renvoie un itérateur qui fournit l'ensem Ce symbole est utilisé par {{jsxref("String.prototype.matchAll()")}} et plus particulièrement par {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}}. Les deux lignes qui suivent renverront le même résultat : ```js -'abc'.matchAll(/a/); +"abc".matchAll(/a/); -/a/[Symbol.matchAll]('abc'); +/a/[Symbol.matchAll]("abc"); ``` Cette méthode existe afin de personnaliser le comportement des correspondances pour les sous-classes de {{jsxref("RegExp")}}. diff --git a/files/fr/web/javascript/reference/global_objects/symbol/species/index.md b/files/fr/web/javascript/reference/global_objects/symbol/species/index.md index df24dd06a9d750..5c77cb90e61447 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/species/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/species/index.md @@ -23,13 +23,15 @@ Dans certains cas, vous pouvez avoir besoin de renvoyer {{jsxref("Array")}} pour ```js class MonArray extends Array { // On surcharge species avec le constructeur parent Array - static get [Symbol.species]() { return Array; } + static get [Symbol.species]() { + return Array; + } } -var a = new MonArray(1,2,3); -var mapped = a.map(x => x * x); +var a = new MonArray(1, 2, 3); +var mapped = a.map((x) => x * x); console.log(mapped instanceof MonArray); // false -console.log(mapped instanceof Array); // true +console.log(mapped instanceof Array); // true ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/symbol/symbol/index.md b/files/fr/web/javascript/reference/global_objects/symbol/symbol/index.md index 843ca7250ee91f..ddff02aa76685f 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/symbol/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/symbol/index.md @@ -13,8 +13,8 @@ Le constructeur `Symbol()` renvoie une valeur de type **`symbol`**. Ce n'est pas ## Syntaxe ```js -Symbol() -Symbol(description) +Symbol(); +Symbol(description); ``` ### Paramètres @@ -30,14 +30,14 @@ Pour créer un nouveau symbole primitif, on écrit `Symbol()` en fournissant év ```js let sym1 = Symbol(); -let sym2 = Symbol('toto'); -let sym3 = Symbol('toto'); +let sym2 = Symbol("toto"); +let sym3 = Symbol("toto"); ``` Dans le code précédent, on crée trois nouveaux symboles. On notera que `Symbol("toto")` ne convertit pas la chaîne de caractères `"toto"` en un symbole. C'est bien un nouveau symbole qui est créé chaque fois : ```js -Symbol('toto') === Symbol('toto'); // false +Symbol("toto") === Symbol("toto"); // false ``` ### `new Symbol(…)` @@ -45,7 +45,7 @@ Symbol('toto') === Symbol('toto'); // false La syntaxe qui suit, utilisant l'opérateur [`new`](/fr/docs/Web/JavaScript/Reference/Operators/new), déclenchera une exception [`TypeError`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypeError) : ```js -let sym = new Symbol(); // TypeError +let sym = new Symbol(); // TypeError ``` Cela permet d'éviter aux développeuses et développeurs de créer un objet enveloppant une valeur symbole primitive plutôt qu'un nouveau symbole. Ce comportement se distingue des autres types de données primitifs pour lesquels c'est possible (par exemple `new Boolean()`, `new String()` et `new Number()`). @@ -53,9 +53,9 @@ Cela permet d'éviter aux développeuses et développeurs de créer un objet env Si on souhaite vraiment envelopper un symbole dans une valeur objet, il faudra utiliser la fonction `Object()` : ```js -let sym = Symbol('toto'); +let sym = Symbol("toto"); let symObj = Object(sym); -typeof sym; // => "symbol" +typeof sym; // => "symbol" typeof symObj; // => "object" ``` diff --git a/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md b/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md index ec47891bb6bc48..0d9ac0eba692a5 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md @@ -23,7 +23,7 @@ Dans l'exemple qui suit, on voit comment la propriété `Symbol.toPrimitive` peu ```js // Premier cas avec un objet sans Symbol.toPrimitive. let obj1 = {}; -console.log(+obj1); // NaN +console.log(+obj1); // NaN console.log(`${obj1}`); // "[object Object]" console.log(obj1 + ""); // "[object Object]" @@ -37,9 +37,9 @@ var obj2 = { return "coucou"; } return true; - } + }, }; -console.log(+obj2); // 10 -- hint vaut "number" +console.log(+obj2); // 10 -- hint vaut "number" console.log(`${obj2}`); // "coucou" -- hint vaut "string" console.log(obj2 + ""); // true -- hint vaut "default" ``` diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md b/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md index 1beb5bdb5ac868..ed07311b5239b5 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md @@ -29,19 +29,19 @@ L'objet {{jsxref("Symbol")}} surcharge la méthode `toString()` d'{{jsxref("Obje Bien qu'il soit possible d'appeler `toString()` pour les symboles, il n'est pas possible de concaténer une chaîne de caractères avec ce type d'objet : ```js -Symbol("toto") + "machin"; // TypeError : Impossible de convertir un symbole en chaîne de caractères +Symbol("toto") + "machin"; // TypeError : Impossible de convertir un symbole en chaîne de caractères ``` ## Exemples ```js -Symbol("desc").toString(); // "Symbol(desc)" +Symbol("desc").toString(); // "Symbol(desc)" // symboles connus -Symbol.iterator.toString(); // "Symbol(Symbol.iterator) +Symbol.iterator.toString(); // "Symbol(Symbol.iterator) // symboles globaux -Symbol.for("toto").toString() // "Symbol(toto)" +Symbol.for("toto").toString(); // "Symbol(toto)" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md b/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md index 0b9c81d0353c74..0005a89c92cc04 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md @@ -15,20 +15,20 @@ Le symbole connu **`Symbol.toStringTag`** est une propriété qui est une chaîn La plupart des types JavaScript ont des étiquettes par défaut : ```js -Object.prototype.toString.call('toto'); // "[object String]" -Object.prototype.toString.call([1, 2]); // "[object Array]" -Object.prototype.toString.call(3); // "[object Number]" -Object.prototype.toString.call(true); // "[object Boolean]" +Object.prototype.toString.call("toto"); // "[object String]" +Object.prototype.toString.call([1, 2]); // "[object Array]" +Object.prototype.toString.call(3); // "[object Number]" +Object.prototype.toString.call(true); // "[object Boolean]" Object.prototype.toString.call(undefined); // "[object Undefined]" -Object.prototype.toString.call(null); // "[object Null]" +Object.prototype.toString.call(null); // "[object Null]" // etc. ``` D'autres ont le symbole natif `toStringTag` défini : ```js -Object.prototype.toString.call(new Map()); // "[object Map]" -Object.prototype.toString.call(function* () {}); // "[object GeneratorFunction]" +Object.prototype.toString.call(new Map()); // "[object Map]" +Object.prototype.toString.call(function* () {}); // "[object GeneratorFunction]" Object.prototype.toString.call(Promise.resolve()); // "[object Promise]" // etc. ``` diff --git a/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md b/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md index 29c8728884e4ae..b175dbe3ca66b6 100644 --- a/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md +++ b/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md @@ -25,7 +25,7 @@ Le code qui suit fonctionne bien pour ES5 et les versions antérieures. En revan ```js var keys = []; -with(Array.prototype) { +with (Array.prototype) { keys.push("something"); } @@ -39,15 +39,15 @@ On peut également manipuler `unscopables` sur ses propres objets : ```js var obj = { toto: 1, - truc: 2 + truc: 2, }; obj[Symbol.unscopables] = { toto: false, - truc: true + truc: true, }; -with(obj) { +with (obj) { console.log(toto); // 1 console.log(truc); // ReferenceError: truc is not defined } diff --git a/files/fr/web/javascript/reference/global_objects/syntaxerror/index.md b/files/fr/web/javascript/reference/global_objects/syntaxerror/index.md index ff7d8880851e81..d78886784a70b3 100644 --- a/files/fr/web/javascript/reference/global_objects/syntaxerror/index.md +++ b/files/fr/web/javascript/reference/global_objects/syntaxerror/index.md @@ -32,15 +32,15 @@ L'objet **`SyntaxError`** représente une erreur qui se produit lors de l'interp ```js try { - eval('toto truc'); + eval("toto truc"); } catch (e) { console.log(e instanceof SyntaxError); // true - console.log(e.message); // "missing ; before statement" - console.log(e.name); // "SyntaxError" - console.log(e.fileName); // "Scratchpad/1" - console.log(e.lineNumber); // 1 - console.log(e.columnNumber); // 4 - console.log(e.stack); // "@Scratchpad/1:2:3\n" + console.log(e.message); // "missing ; before statement" + console.log(e.name); // "SyntaxError" + console.log(e.fileName); // "Scratchpad/1" + console.log(e.lineNumber); // 1 + console.log(e.columnNumber); // 4 + console.log(e.stack); // "@Scratchpad/1:2:3\n" } ``` @@ -48,15 +48,15 @@ try { ```js try { - throw new SyntaxError('Coucou', 'unFichier.js', 10); + throw new SyntaxError("Coucou", "unFichier.js", 10); } catch (e) { console.log(e instanceof SyntaxError); // true - console.log(e.message); // "Coucou" - console.log(e.name); // "SyntaxError" - console.log(e.fileName); // "unFichier.js" - console.log(e.lineNumber); // 10 - console.log(e.columnNumber); // 0 - console.log(e.stack); // "@Scratchpad/2:11:9\n" + console.log(e.message); // "Coucou" + console.log(e.name); // "SyntaxError" + console.log(e.fileName); // "unFichier.js" + console.log(e.lineNumber); // 10 + console.log(e.columnNumber); // 0 + console.log(e.stack); // "@Scratchpad/2:11:9\n" } ``` diff --git a/files/fr/web/javascript/reference/global_objects/syntaxerror/syntaxerror/index.md b/files/fr/web/javascript/reference/global_objects/syntaxerror/syntaxerror/index.md index 349d34b88426fa..0d172f49ab6f07 100644 --- a/files/fr/web/javascript/reference/global_objects/syntaxerror/syntaxerror/index.md +++ b/files/fr/web/javascript/reference/global_objects/syntaxerror/syntaxerror/index.md @@ -11,10 +11,10 @@ Le constructeur **`SyntaxError()`** permet de créer un objet représentant une ## Syntaxe ```js -new SyntaxError() -new SyntaxError(message) -new SyntaxError(message, nomFichier) -new SyntaxError(message, nomFichier, numeroLigne) +new SyntaxError(); +new SyntaxError(message); +new SyntaxError(message, nomFichier); +new SyntaxError(message, nomFichier, numeroLigne); ``` ### Paramètres @@ -32,7 +32,7 @@ new SyntaxError(message, nomFichier, numeroLigne) ```js try { - eval('coucou truc'); + eval("coucou truc"); } catch (e) { console.error(e instanceof SyntaxError); console.error(e.message); @@ -48,15 +48,15 @@ try { ```js try { - throw new SyntaxError('Coucou', 'unFichier.js', 10); + throw new SyntaxError("Coucou", "unFichier.js", 10); } catch (e) { console.error(e instanceof SyntaxError); // true - console.error(e.message); // Coucou - console.error(e.name); // SyntaxError - console.error(e.fileName); // unFichier.js - console.error(e.lineNumber); // 10 - console.error(e.columnNumber); // 0 - console.error(e.stack); // @debugger eval code:3:9 + console.error(e.message); // Coucou + console.error(e.name); // SyntaxError + console.error(e.fileName); // unFichier.js + console.error(e.lineNumber); // 10 + console.error(e.columnNumber); // 0 + console.error(e.stack); // @debugger eval code:3:9 } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/@@iterator/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/@@iterator/index.md index d4dc2709a75610..3b7a534869d78d 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/@@iterator/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/@@iterator/index.md @@ -11,7 +11,7 @@ La valeur initiale de la propriété @@iterator est le même objet fonction que ## Syntaxe ```js -typedarray[Symbol.iterator]() +typedarray[Symbol.iterator](); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/@@species/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/@@species/index.md index b0f77650088106..c058e6eb4465aa 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/@@species/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/@@species/index.md @@ -11,7 +11,7 @@ La propriété d'accesseur **`TypedArray[@@species]`** renvoie le constructeur [ ## Syntaxe ```js -TypedArray[Symbol.species] +TypedArray[Symbol.species]; ``` où TypedArray vaut : @@ -35,8 +35,8 @@ L'accesseur `species` renvoie le constructeur par défaut pour les tableaux typ La propriété `species` renvoie le constructeur par défaut qui est l'un des constructeurs de tableau typé (selon le type [de tableau typé](/fr/docs/Web/JavaScript/Reference/Objets_globaux/TypedArray#Les_objets_TypedArray) de l'objet) : ```js -Int8Array[Symbol.species]; // function Int8Array() -Uint8Array[Symbol.species]; // function Uint8Array() +Int8Array[Symbol.species]; // function Int8Array() +Uint8Array[Symbol.species]; // function Uint8Array() Float32Array[Symbol.species]; // function Float32Array() ``` @@ -46,7 +46,9 @@ Pour un objet construit sur mesure (par exemple une tableau `MonTableauTypé`), class MonTableauTypé extends Uint8Array { // On surcharge species pour MonTableauTypé // pour récupérer le constructeur Uint8Array - static get [Symbol.species]() { return Uint8Array; } + static get [Symbol.species]() { + return Uint8Array; + } } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/at/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/at/index.md index ed92a1d9a6fc44..37cd46bad49791 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/at/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/at/index.md @@ -15,7 +15,7 @@ L'accès aux éléments d'un tableau typé en utilisant les crochets ne permet q ## Syntaxe ```js -at(indice) +at(indice); ``` ### Paramètres @@ -54,7 +54,7 @@ On compare ici différentes façons d'accéder à l'avant-dernier élément d'un const uint8 = new Uint8Array([1, 2, 4, 7, 11, 18]); // En utilisant la propriété length -const avecLength = uint8[uint8.length-2]; +const avecLength = uint8[uint8.length - 2]; console.log(avecLength); // Affiche 11 dans la console // En utilisant la méthode slice() diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/buffer/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/buffer/index.md index db68605d85e4c8..3ab4d3d12efc76 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/buffer/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/buffer/index.md @@ -13,7 +13,7 @@ La propriété **`buffer`** est un accesseur représentant l'{{jsxref("ArrayBuff ## Syntaxe ```js -typedArray.buffer +typedArray.buffer; ``` ## Description diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/bytelength/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/bytelength/index.md index fb28812f5ae5d7..f2b5118bc1359b 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/bytelength/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/bytelength/index.md @@ -13,7 +13,7 @@ La propriété **`byteLength`** est un accesseur qui représente la longueur, ex ## Syntaxe ```js -typedarray.byteLength +typedarray.byteLength; ``` ## Description diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/byteoffset/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/byteoffset/index.md index 550e69e0af2349..925ad14306f16d 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/byteoffset/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/byteoffset/index.md @@ -11,7 +11,7 @@ La propriété **`byteOffset`** est un accesseur qui représente le décalage, e ## Syntaxe ```js -typedarray.byteOffset +typedarray.byteOffset; ``` ## Description diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.md index 1e2d7cf27b2903..439bbacfb02eee 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.md @@ -23,15 +23,15 @@ La taille des éléments d'un tableau typé varie en fonction du type de `TypedA ## Exemples ```js -Int8Array.BYTES_PER_ELEMENT; // 1 -Uint8Array.BYTES_PER_ELEMENT; // 1 +Int8Array.BYTES_PER_ELEMENT; // 1 +Uint8Array.BYTES_PER_ELEMENT; // 1 Uint8ClampedArray.BYTES_PER_ELEMENT; // 1 -Int16Array.BYTES_PER_ELEMENT; // 2 -Uint16Array.BYTES_PER_ELEMENT; // 2 -Int32Array.BYTES_PER_ELEMENT; // 4 -Uint32Array.BYTES_PER_ELEMENT; // 4 -Float32Array.BYTES_PER_ELEMENT; // 4 -Float64Array.BYTES_PER_ELEMENT; // 8 +Int16Array.BYTES_PER_ELEMENT; // 2 +Uint16Array.BYTES_PER_ELEMENT; // 2 +Int32Array.BYTES_PER_ELEMENT; // 4 +Uint32Array.BYTES_PER_ELEMENT; // 4 +Float32Array.BYTES_PER_ELEMENT; // 4 +Float64Array.BYTES_PER_ELEMENT; // 8 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/copywithin/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/copywithin/index.md index 0189eead32d620..6362afb71ca0f2 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/copywithin/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/copywithin/index.md @@ -40,9 +40,9 @@ Cette méthode remplace la méthode expérimentale {{jsxref("TypedArray.prototyp ```js var buffer = new ArrayBuffer(8); var uint8 = new Uint8Array(buffer); -uint8.set([1,2,3]); +uint8.set([1, 2, 3]); console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ] -uint8.copyWithin(3,0,3); +uint8.copyWithin(3, 0, 3); console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ] ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/entries/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/entries/index.md index d77671fee65aac..70caa1940304a5 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/entries/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/entries/index.md @@ -13,7 +13,7 @@ La méthode **`entries()`** renvoie un nouvel objet `Array Iterator` qui contien ## Syntaxe ```js -arr.entries() +arr.entries(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/every/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/every/index.md index 56b45c050a2695..49499efd2235bc 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/every/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/every/index.md @@ -56,7 +56,7 @@ Dans l'exemple suivant, on teste si tous les éléments du tableau typé sont su function estGrand(element, index, array) { return element >= 10; } -new Uint8Array([12, 5, 8, 130, 44]).every(estGrand); // false +new Uint8Array([12, 5, 8, 130, 44]).every(estGrand); // false new Uint8Array([12, 54, 18, 130, 44]).every(estGrand); // true ``` @@ -65,8 +65,8 @@ new Uint8Array([12, 54, 18, 130, 44]).every(estGrand); // true [Les fonctions fléchées](/fr/docs/Web/JavaScript/Reference/Fonctions/Fonctions_fléchées) permettent d'utiliser une syntaxe plus concise pour parvenir au même résultat : ```js -new Uint8Array([12, 5, 8, 130, 44]).every(elem => elem >= 10); // false -new Uint8Array([12, 54, 18, 130, 44]).every(elem => elem >= 10); // true +new Uint8Array([12, 5, 8, 130, 44]).every((elem) => elem >= 10); // false +new Uint8Array([12, 54, 18, 130, 44]).every((elem) => elem >= 10); // true ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/fill/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/fill/index.md index 0c5d22e1a63274..8bd9c437c5a193 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/fill/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/fill/index.md @@ -40,10 +40,10 @@ Si `début` est négatif, on le traite comme `length+début` où `length` repré ## Exemples ```js -new Uint8Array([1, 2, 3]).fill(4); // Uint8Array [4, 4, 4] -new Uint8Array([1, 2, 3]).fill(4, 1); // Uint8Array [1, 4, 4] -new Uint8Array([1, 2, 3]).fill(4, 1, 2); // Uint8Array [1, 4, 3] -new Uint8Array([1, 2, 3]).fill(4, 1, 1); // Uint8Array [1, 2, 3] +new Uint8Array([1, 2, 3]).fill(4); // Uint8Array [4, 4, 4] +new Uint8Array([1, 2, 3]).fill(4, 1); // Uint8Array [1, 4, 4] +new Uint8Array([1, 2, 3]).fill(4, 1, 2); // Uint8Array [1, 4, 3] +new Uint8Array([1, 2, 3]).fill(4, 1, 1); // Uint8Array [1, 2, 3] new Uint8Array([1, 2, 3]).fill(4, -3, -2); // Uint8Array [4, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/filter/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/filter/index.md index 08ad3f205f53f5..b21f3bdd174034 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/filter/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/filter/index.md @@ -62,7 +62,7 @@ new Uint8Array([12, 5, 8, 130, 44]).filter(supSeuil); [Les fonctions fléchées](/fr/docs/Web/JavaScript/Reference/Fonctions/Fonctions_fléchées) permettent d'utiliser une syntaxe plus concise pour réaliser le même test que montré précédemment : ```js -new Uint8Array([12, 5, 8, 130, 44]).filter(élém => élém >= 10); +new Uint8Array([12, 5, 8, 130, 44]).filter((élém) => élém >= 10); // Uint8Array [ 12, 130, 44 ] ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/foreach/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/foreach/index.md index f7b65ea9a4608b..9317821c2a1ce9 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/foreach/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/foreach/index.md @@ -58,7 +58,7 @@ Le code ci-dessous affiche une ligne pour chaque élément du tableau typé : ```js function affichageContenuTableau(élément, index, tableau) { - console.log('a[' + index + '] = ' + élément); + console.log("a[" + index + "] = " + élément); } new Uint8Array([0, 1, 2, 3]).forEach(affichageContenuTableau); diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/from/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/from/index.md index 4837102e9a465e..7f71965443c515 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/from/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/from/index.md @@ -65,20 +65,17 @@ var s = new Set([1, 2, 3]); Uint8Array.from(s); // Uint8Array [ 1, 2, 3 ] - // String Int16Array.from("123"); // Int16Array [ 1, 2, 3 ] - // En utilisant un fonction fléchée en tant que // fonctionMap pour manipuler les éléments -Float32Array.from([1, 2, 3], x => x + x); +Float32Array.from([1, 2, 3], (x) => x + x); // Float32Array [ 2, 4, 6 ] - // Pour construire une séquence de nombres -Uint8Array.from({length: 5}, (v, k) => k); +Uint8Array.from({ length: 5 }, (v, k) => k); // Uint8Array [ 0, 1, 2, 3, 4 ] ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/includes/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/includes/index.md index f9461dc4389b41..dc8556c2078ea2 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/includes/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/includes/index.md @@ -30,10 +30,10 @@ Un booléen indiquant la présence de l'élément (`true` s'il y est, `false` si ## Exemples ```js -var uint8 = new Uint8Array([1,2,3]); -uint8.includes(2); // true -uint8.includes(4); // false -uint8.includes(3, 3); // false +var uint8 = new Uint8Array([1, 2, 3]); +uint8.includes(2); // true +uint8.includes(4); // false +uint8.includes(3, 3); // false // Gestion de NaN (vrai uniquement pour Float32 et Float64) new Uint8Array([NaN]).includes(NaN); // false car NaN est converti en 0 par le constructeur diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/index.md index 9e00545ba0fc89..39aa282ce012ed 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/index.md @@ -18,19 +18,19 @@ Lorsqu'on crée une instance de _TypedArray_ (par exemple, une instance de `Int8 ### Objets _TypedArray_ -| Type | Intervalle de valeurs | Taille en octets | Description | Type Web IDL | Type C équivalent | -| ---------------------------------------- | --------------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------------- | --------------------- | ------------------------------- | -| [`Int8Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) | `-128` à `127` | 1 | Entier sur 8 bits signé en complément à deux | `byte` | `int8_t` | -| [`Uint8Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | `0` à `255` | 1 | Entier non-signé sur 8 bits | `octet` | `uint8_t` | -| [`Uint8ClampedArray`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) | `0` à `255` | 1 | Entier non-signé sur 8 bits (écrété) | `octet` | `uint8_t` | -| [`Int16Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) | `-32768` à `32767` | 2 | Entier sur 16 bits, signé en complément à deux | `short` | `int16_t` | -| [`Uint16Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) | `0` à `65535` | 2 | Entier non-signé sur 16 bits | `unsigned short` | `uint16_t` | -| [`Int32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) | `-2147483648` à `2147483647` | 4 | Entier sur 32 bits, signé en complément à deux | `long` | `int32_t` | -| [`Uint32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) | `0` à `4294967295` | 4 | Entier sur 32 bits non-signé | `unsigned long` | `uint32_t` | -| [`Float32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) | `-3.4E38` à `3.4E38` avec `1.2E-38` le plus petit nombre positif | 4 | Nombre flottant sur 32 bits au format IEEE avec 7 chiffres significatifs (par exemple `1.234567`) | `unrestricted float` | `float` | -| [`Float64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) | `-1.8E308` à `1.8E308` avec `5E-324` le plus petit nombre positif | 8 | Nombre flottant sur 64 bits au format IEEE avec 16 chiffres significatifs (par exemple `1.23456789012345`) | `unrestricted double` | `double` | -| [`BigInt64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array) | `-2^63` à `2^63 - 1` | 8 | Entier sur 64 bits, signé en complément à deux integer | `bigint` | `int64_t (signed long long)` | -| [`BigUint64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array) | `0` à `2^64 - 1` | 8 | Entier sur 64 bits non-signé | `bigint` | `uint64_t (unsigned long long)` | +| Type | Intervalle de valeurs | Taille en octets | Description | Type Web IDL | Type C équivalent | +| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------- | +| [`Int8Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) | `-128` à `127` | 1 | Entier sur 8 bits signé en complément à deux | `byte` | `int8_t` | +| [`Uint8Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | `0` à `255` | 1 | Entier non-signé sur 8 bits | `octet` | `uint8_t` | +| [`Uint8ClampedArray`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) | `0` à `255` | 1 | Entier non-signé sur 8 bits (écrété) | `octet` | `uint8_t` | +| [`Int16Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) | `-32768` à `32767` | 2 | Entier sur 16 bits, signé en complément à deux | `short` | `int16_t` | +| [`Uint16Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) | `0` à `65535` | 2 | Entier non-signé sur 16 bits | `unsigned short` | `uint16_t` | +| [`Int32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) | `-2147483648` à `2147483647` | 4 | Entier sur 32 bits, signé en complément à deux | `long` | `int32_t` | +| [`Uint32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) | `0` à `4294967295` | 4 | Entier sur 32 bits non-signé | `unsigned long` | `uint32_t` | +| [`Float32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) | `-3.4E38` à `3.4E38` avec `1.2E-38` le plus petit nombre positif | 4 | Nombre flottant sur 32 bits au format IEEE avec 7 chiffres significatifs (par exemple `1.234567`) | `unrestricted float` | `float` | +| [`Float64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) | `-1.8E308` à `1.8E308` avec `5E-324` le plus petit nombre positif | 8 | Nombre flottant sur 64 bits au format IEEE avec 16 chiffres significatifs (par exemple `1.23456789012345`) | `unrestricted double` | `double` | +| [`BigInt64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array) | `-2^63` à `2^63 - 1` | 8 | Entier sur 64 bits, signé en complément à deux integer | `bigint` | `int64_t (signed long long)` | +| [`BigUint64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array) | `0` à `2^64 - 1` | 8 | Entier sur 64 bits non-signé | `bigint` | `uint64_t (unsigned long long)` | ## Constructeur @@ -56,7 +56,7 @@ Où _TypedArray_ est un constructeur donné pour un type de tableau typé exista - : Lorsque le constructeur est appelé avec un argument `longueur`, un tampon de mémoire interne sous forme de tableau est créé et dont la taille est `longueur` multipliée par `BYTES_PER_ELEMENT` octets. Chaque élément du tableau contient des zéros. - `tableauType` - : Lorsque le constructeur est appelé avec un argument `tableauType`, `tableauType` est copié dans un nouveau tableau typé. Pour un tableay typé **dont le type n'est pas [`BigInt64Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)**, le paramètre peut être un objet de n'importe quel type de tableau typé en dehors de `BigInt64Array` (par exemple [`Int32Array`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Int32Array)). L'inverse est aussi valable, pour obtenir un tableau typé `BigInt64Array`, le paramètre devra nécessairement être de type `BigInt64Array`. - Chaque valeur contenue dans `tableauType` est convertie dans le type correspondant au constructeur avant d'être copiée dans le nouveau tableau. La longueur du nouveau tableau typé sera la même que celle de l'argument `tableauType`. + Chaque valeur contenue dans `tableauType` est convertie dans le type correspondant au constructeur avant d'être copiée dans le nouveau tableau. La longueur du nouveau tableau typé sera la même que celle de l'argument `tableauType`. - `objet` - : Lorsque le constructeur est appelé avec un objet comme argument, un nouveau tableau typé est créé à la façon de la méthode `TypedArray.from()`. - `buffer`, `decalageOctet`, `longueur` @@ -177,17 +177,17 @@ console.log(int16[0]); // 42 // Les propriétés indexées sur les prototypes ne sont pas consultées Int8Array.prototype[20] = "toto"; -(new Int8Array(32))[20]; // 0 +new Int8Array(32)[20]; // 0 // y compris en dehors des limites Int8Array.prototype[20] = "toto"; -(new Int8Array(8))[20]; // undefined +new Int8Array(8)[20]; // undefined // ou avec des index négatifs Int8Array.prototype[-1] = "toto"; -(new Int8Array(8))[-1]; // undefined +new Int8Array(8)[-1]; // undefined // Mais il est possible d'utiliser des propriétés nommées Int8Array.prototype.toto = "truc"; -(new Int8Array(32)).toto; // "truc" +new Int8Array(32).toto; // "truc" ``` ### Impossibles à geler diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/indexof/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/indexof/index.md index 5bdecc1f2bf19a..618fe32be03c3a 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/indexof/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/indexof/index.md @@ -35,9 +35,9 @@ Le premier indice du tableau pour lequel l'élément a été trouvé, `-1` s'il ```js var uint8 = new Uint8Array([2, 5, 9]); -uint8.indexOf(2); // 0 -uint8.indexOf(7); // -1 -uint8.indexOf(9, 2); // 2 +uint8.indexOf(2); // 0 +uint8.indexOf(7); // -1 +uint8.indexOf(9, 2); // 2 uint8.indexOf(2, -1); // -1 uint8.indexOf(2, -3); // 0 ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/join/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/join/index.md index 06c5746476a4df..22df17869c4945 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/join/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/join/index.md @@ -13,7 +13,7 @@ La méthode **`join()`** fusionne l'ensemble des éléments d'un tableau en une ## Syntaxe ```js -typedarray.join([séparateur = ',']); +typedarray.join([(séparateur = ",")]); ``` ### Paramètres @@ -28,10 +28,10 @@ Une chaîne de caractères formée par la concaténation des différents éléme ## Exemples ```js -var uint8 = new Uint8Array([1,2,3]); -uint8.join(); // '1,2,3' -uint8.join(' / '); // '1 / 2 / 3' -uint8.join(''); // '123' +var uint8 = new Uint8Array([1, 2, 3]); +uint8.join(); // '1,2,3' +uint8.join(" / "); // '1 / 2 / 3' +uint8.join(""); // '123' ``` ## Prothèse d'émulation (_polyfill_) @@ -41,8 +41,8 @@ Il n'existe pas d'objet global _TypedArray_, il faut donc ajouter une prothèse ```js // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.join if (!Uint8Array.prototype.join) { - Object.defineProperty(Uint8Array.prototype, 'join', { - value: Array.prototype.join + Object.defineProperty(Uint8Array.prototype, "join", { + value: Array.prototype.join, }); } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/keys/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/keys/index.md index fe3ce161cacffe..2793cb036ca5e6 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/keys/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/keys/index.md @@ -13,7 +13,7 @@ La méthode **`keys()`** renvoie un nouvel objet `Array Iterator` contenant les ## Syntaxe ```js -arr.keys() +arr.keys(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/lastindexof/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/lastindexof/index.md index 4a5458fe683434..c0b5c5a313396c 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/lastindexof/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/lastindexof/index.md @@ -6,7 +6,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/TypedArray/lastIndexOf {{JSRef}} -La méthode **`lastIndexOf()`** renvoie le dernier indice (le plus grand) pour lequel un élément donné est trouvé. Si l'élément cherché n'est pas trouvé, la valeur de retour sera -1. Le tableau typé est parcouru dans l'ordre des indices décroissants (de la fin vers le début) à partir de `indexDépart`. Cette méthode utilise le même algorithme que {{jsxref("Array.prototype.lastIndexOf()")}}. Dans le reste de l'article, *TypedArray* correspond à l'un des [types de tableaux typés](/fr/docs/Web/JavaScript/Reference/Objets_globaux/TypedArray#Les_objets_TypedArray). +La méthode **`lastIndexOf()`** renvoie le dernier indice (le plus grand) pour lequel un élément donné est trouvé. Si l'élément cherché n'est pas trouvé, la valeur de retour sera -1. Le tableau typé est parcouru dans l'ordre des indices décroissants (de la fin vers le début) à partir de `indexDépart`. Cette méthode utilise le même algorithme que {{jsxref("Array.prototype.lastIndexOf()")}}. Dans le reste de l'article, _TypedArray_ correspond à l'un des [types de tableaux typés](/fr/docs/Web/JavaScript/Reference/Objets_globaux/TypedArray#Les_objets_TypedArray). {{EmbedInteractiveExample("pages/js/typedarray-lastindexof.html")}} @@ -35,10 +35,10 @@ Le dernier indice du tableau typé pour lequel l'élément a été trouvé ou `- ```js var uint8 = new Uint8Array([2, 5, 9, 2]); -uint8.lastIndexOf(2); // 3 -uint8.lastIndexOf(7); // -1 -uint8.lastIndexOf(2, 3); // 3 -uint8.lastIndexOf(2, 2); // 0 +uint8.lastIndexOf(2); // 3 +uint8.lastIndexOf(7); // -1 +uint8.lastIndexOf(2, 3); // 3 +uint8.lastIndexOf(2, 2); // 0 uint8.lastIndexOf(2, -2); // 0 uint8.lastIndexOf(2, -1); // 3 ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/length/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/length/index.md index 096c1a92a97c27..5af9320aea5436 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/length/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/length/index.md @@ -13,7 +13,7 @@ La propriété **`length`** est un accesseur qui permet de représenter la longu ## Syntaxe ```js -typedarray.length +typedarray.length; ``` ## Description diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/map/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/map/index.md index a3cf4cc354c50f..d5d09a61bf5bca 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/map/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/map/index.md @@ -67,7 +67,7 @@ Ici, on illustre comment une fonction utilisant un argument peut être utilisée ```js var nombres = new Uint8Array([1, 4, 9]); -var doubles = nombres.map(function(num) { +var doubles = nombres.map(function (num) { return num * 2; }); // doubles vaut désormais Uint8Array [2, 8, 18] diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/of/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/of/index.md index 35387bf3cd7e0d..3c9b914b7efcf4 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/of/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/of/index.md @@ -47,10 +47,10 @@ Il existe de légères différences entre {{jsxref("Array.of()")}} et `TypedArra ## Exemples ```js -Uint8Array.of(1); // Uint8Array [ 1 ] +Uint8Array.of(1); // Uint8Array [ 1 ] Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ] -Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ] -Int16Array.of(undefined); // Int16Array [ 0 ] +Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ] +Int16Array.of(undefined); // Int16Array [ 0 ] ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/reduce/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/reduce/index.md index 5409d9c53275cb..e8011592320d75 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/reduce/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/reduce/index.md @@ -49,7 +49,7 @@ Si le tableau typé est vide et que le paramètre `valeurInitiale` n'a pas été ## Exemples ```js -var total = new Uint8Array([0, 1, 2, 3]).reduce(function(a, b) { +var total = new Uint8Array([0, 1, 2, 3]).reduce(function (a, b) { return a + b; }); // total == 6 diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/reduceright/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/reduceright/index.md index b9580f53208a73..804f8290ada019 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/reduceright/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/reduceright/index.md @@ -43,9 +43,11 @@ La méthode `reduceRight` exécute la fonction `callback` une fois pour chaque L'appel à `reduceRight` utilisant la fonction `callback` ressemble à : ```js -typedarray.reduceRight(function(valeurPrécédente, valeurCourante, index, typedarray) { - // ... -}); +typedarray.reduceRight( + function (valeurPrécédente, valeurCourante, index, typedarray) { + // ... + }, +); ``` Lors du premier appel à la fonction callback, `valeurPrécédente` et `valeurCourante` peuvent être un ou deux valeurs différentes. Si `valeurInitiale` est fournie, `valeurPrécédente` sera alors égale à `valeurInitiale` et `valeurCourante` sera égale à la première valeur du tableau. Si le paramètre `valeurInitiale` n'est pas utilisé, `valeurPrécédente` sera égale au premier élément du tableau typé et `valeurCourante` sera égale au second élément. @@ -55,7 +57,7 @@ Si le tableau typé est vide et que le paramètre `valeurInitiale` n'a pas été ## Exemples ```js -var total = new Uint8Array([0, 1, 2, 3]).reduceRight(function(a, b) { +var total = new Uint8Array([0, 1, 2, 3]).reduceRight(function (a, b) { return a + b; }); // total == 6 diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/slice/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/slice/index.md index bede5dde9b4df1..6ed52c8fb7ac31 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/slice/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/slice/index.md @@ -36,11 +36,11 @@ Si un nouvel élément est ajouté à l'un des deux tableaux typés, l'autre ne ## Exemples ```js -var uint8 = new Uint8Array([1,2,3]); -uint8.slice(1); // Uint8Array [ 2, 3 ] -uint8.slice(2); // Uint8Array [ 3 ] -uint8.slice(-2); // Uint8Array [ 2, 3 ] -uint8.slice(0,1); // Uint8Array [ 1 ] +var uint8 = new Uint8Array([1, 2, 3]); +uint8.slice(1); // Uint8Array [ 2, 3 ] +uint8.slice(2); // Uint8Array [ 3 ] +uint8.slice(-2); // Uint8Array [ 2, 3 ] +uint8.slice(0, 1); // Uint8Array [ 1 ] ``` ## Prothèse d'émulation (_polyfill_) @@ -50,10 +50,10 @@ Il n'existe pas d'objet global intitulé _TypedArray_, la prothèse doit donc un ```js // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.slice if (!Uint8Array.prototype.slice) { - Object.defineProperty(Uint8Array.prototype, 'slice', { - value: function (begin, end){ + Object.defineProperty(Uint8Array.prototype, "slice", { + value: function (begin, end) { return new Uint8Array(Array.prototype.slice.call(this, begin, end)); - } + }, }); } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/some/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/some/index.md index b7a4a1d057cf4a..edf66ab8b06056 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/some/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/some/index.md @@ -56,7 +56,7 @@ Dans l'exemple qui suit, on teste s'il existe au moins un élément du tableau t function supérieurÀ10(élément, index, array) { return élément > 10; } -new Uint8Array([2, 5, 8, 1, 4]).some(supérieurÀ10); // false +new Uint8Array([2, 5, 8, 1, 4]).some(supérieurÀ10); // false new Uint8Array([12, 5, 8, 1, 4]).some(supérieurÀ10); // true ``` @@ -65,8 +65,8 @@ new Uint8Array([12, 5, 8, 1, 4]).some(supérieurÀ10); // true [Les fonctions fléchées](/fr/docs/Web/JavaScript/Reference/Functions/Arrow_functions) permettent d'utiliser une syntaxe plus concise pour arriver au même résultat : ```js -new Uint8Array([2, 5, 8, 1, 4]).some(elem => elem > 10); // false -new Uint8Array([12, 5, 8, 1, 4]).some(elem => elem > 10); // true +new Uint8Array([2, 5, 8, 1, 4]).some((elem) => elem > 10); // false +new Uint8Array([12, 5, 8, 1, 4]).some((elem) => elem > 10); // true ``` ## Prothèse d'émulation (_polyfill_) @@ -76,8 +76,8 @@ Il n'existe pas d'objet global intitulé _TypedArray_, la prothèse doit donc un ```js // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.slice if (!Uint8Array.prototype.some) { - Object.defineProperty(Uint8Array.prototype, 'some', { - value: Array.prototype.some + Object.defineProperty(Uint8Array.prototype, "some", { + value: Array.prototype.some, }); } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/sort/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/sort/index.md index 8abfa929b091ab..3062f9fbad36d0 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/sort/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/sort/index.md @@ -13,7 +13,7 @@ La méthode **`sort()`** permet de trier numériquement les éléments d'un tabl ## Syntaxe ```js -typedarray.sort([fonctionComparaison]) +typedarray.sort([fonctionComparaison]); ``` ### Paramètres diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/subarray/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/subarray/index.md index b7dd621f846810..c4e7276d8bbb69 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/subarray/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/subarray/index.md @@ -38,13 +38,13 @@ On notera que cette méthode permet de créer un nouvelle vue sur le tampon (_bu ```js var buffer = new ArrayBuffer(8); var uint8 = new Uint8Array(buffer); -uint8.set([1,2,3]); +uint8.set([1, 2, 3]); console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ] -var sub = uint8.subarray(0,4); +var sub = uint8.subarray(0, 4); -console.log(sub); // Uint8Array [ 1, 2, 3, 0 ] +console.log(sub); // Uint8Array [ 1, 2, 3, 0 ] ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/tolocalestring/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/tolocalestring/index.md index efa1f25b292126..8c2bb6d7f805a9 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/tolocalestring/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/tolocalestring/index.md @@ -11,9 +11,9 @@ La méthode **`toLocaleString()`** renvoie une chaîne de caractères qui repré ## Syntaxe ```js -toLocaleString() -toLocaleString(locales) -toLocaleString(locales, options) +toLocaleString(); +toLocaleString(locales); +toLocaleString(locales, options); ``` ### Paramètres @@ -37,10 +37,10 @@ uint.toLocaleString(); // si on exécute sur un environnement utilisant la locale de-DE // "2.000,500,8.123,12,4.212" -uint.toLocaleString('en-US'); +uint.toLocaleString("en-US"); // "2,000,500,8,123,12,4,212" -uint.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }); +uint.toLocaleString("ja-JP", { style: "currency", currency: "JPY" }); // "¥2,000,¥500,¥8,123,¥12,¥4,212" ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/tostring/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/tostring/index.md index 00fe10b90b1d87..65327a0caa72dd 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/tostring/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/tostring/index.md @@ -13,7 +13,7 @@ La méthode **`toString()`** renvoie une chaîne de caractères qui représente ## Syntaxe ```js -typedarray.toString() +typedarray.toString(); ``` ### Valeur de retour @@ -25,7 +25,7 @@ Une chaîne de caractères qui représente les éléments du tableau typé. Les objets {{jsxref("TypedArray")}} surchargent la méthode `toString` de {{jsxref("Object")}}. Pour les objets `TypedArray`, la méthode `toString` fusionne le tableau et renovoie une chaîne de caractères contenant les éléments du tableau, chacun séparés par une virgule. Par exemple : ```js -var numbers = new Uint8Array([2, 5, 8, 1, 4]) +var numbers = new Uint8Array([2, 5, 8, 1, 4]); numbers.toString(); // "2,5,8,1,4" ``` @@ -36,7 +36,7 @@ JavaScript appelle automatiquement la méthode `toString()` lorsqu'un tableau ty Si un navigateur ne prend pas encore en charge la méthode `TypedArray.prototype.toString()`, le moteur JavaScript utilisera la méthode `toString` rattachée à {{jsxref("Object")}} : ```js -var numbers = new Uint8Array([2, 5, 8, 1, 4]) +var numbers = new Uint8Array([2, 5, 8, 1, 4]); numbers.toString(); // "[object Uint8Array]" ``` diff --git a/files/fr/web/javascript/reference/global_objects/typedarray/values/index.md b/files/fr/web/javascript/reference/global_objects/typedarray/values/index.md index afb5a3d9767c41..681f466cc5cf1f 100644 --- a/files/fr/web/javascript/reference/global_objects/typedarray/values/index.md +++ b/files/fr/web/javascript/reference/global_objects/typedarray/values/index.md @@ -13,7 +13,7 @@ La méthode **`values()`** renvoie un nouvel objet `Array Iterator` qui contient ## Syntaxe ```js -typedArr.values() +typedArr.values(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/typeerror/index.md b/files/fr/web/javascript/reference/global_objects/typeerror/index.md index c73b60791e8cea..f8477721806df0 100644 --- a/files/fr/web/javascript/reference/global_objects/typeerror/index.md +++ b/files/fr/web/javascript/reference/global_objects/typeerror/index.md @@ -42,13 +42,13 @@ Une exception `TypeError` peut être levée lorsque : try { null.f(); } catch (e) { - console.log(e instanceof TypeError); // true - console.log(e.message); // "null has no properties" - console.log(e.name); // "TypeError" - console.log(e.fileName); // "Scratchpad/1" - console.log(e.lineNumber); // 2 - console.log(e.columnNumber); // 2 - console.log(e.stack); // "@Scratchpad/2:2:3\n" + console.log(e instanceof TypeError); // true + console.log(e.message); // "null has no properties" + console.log(e.name); // "TypeError" + console.log(e.fileName); // "Scratchpad/1" + console.log(e.lineNumber); // 2 + console.log(e.columnNumber); // 2 + console.log(e.stack); // "@Scratchpad/2:2:3\n" } ``` @@ -56,15 +56,15 @@ try { ```js try { - throw new TypeError('Coucou', 'unFichier.js', 10); + throw new TypeError("Coucou", "unFichier.js", 10); } catch (e) { - console.log(e instanceof TypeError); // true - console.log(e.message); // "Coucou" - console.log(e.name); // "TypeError" - 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" + console.log(e instanceof TypeError); // true + console.log(e.message); // "Coucou" + console.log(e.name); // "TypeError" + 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" } ``` diff --git a/files/fr/web/javascript/reference/global_objects/typeerror/typeerror/index.md b/files/fr/web/javascript/reference/global_objects/typeerror/typeerror/index.md index 7fe44d70786d76..480a72315ecd87 100644 --- a/files/fr/web/javascript/reference/global_objects/typeerror/typeerror/index.md +++ b/files/fr/web/javascript/reference/global_objects/typeerror/typeerror/index.md @@ -11,10 +11,10 @@ Le constructeur **`TypeError()`** permet de créer un objet représentant une er ## Syntaxe ```js -new TypeError() -new TypeError(message) -new TypeError(message, nomFichier) -new TypeError(message, nomFichier, numeroLigne) +new TypeError(); +new TypeError(message); +new TypeError(message, nomFichier); +new TypeError(message, nomFichier, numeroLigne); ``` ### Paramètres @@ -34,13 +34,13 @@ new TypeError(message, nomFichier, numeroLigne) try { null.f(); } catch (e) { - console.log(e instanceof TypeError); // true - console.log(e.message); // "null has no properties" - console.log(e.name); // "TypeError" - console.log(e.fileName); // "Scratchpad/1" - console.log(e.lineNumber); // 2 - console.log(e.columnNumber); // 2 - console.log(e.stack); // "@Scratchpad/2:2:3\n" + console.log(e instanceof TypeError); // true + console.log(e.message); // "null has no properties" + console.log(e.name); // "TypeError" + console.log(e.fileName); // "Scratchpad/1" + console.log(e.lineNumber); // 2 + console.log(e.columnNumber); // 2 + console.log(e.stack); // "@Scratchpad/2:2:3\n" } ``` @@ -48,15 +48,15 @@ try { ```js try { - throw new TypeError('Coucou', 'unFichier.js', 10); + throw new TypeError("Coucou", "unFichier.js", 10); } catch (e) { - console.log(e instanceof TypeError); // true - console.log(e.message); // "Coucou" - console.log(e.name); // "TypeError" - 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" + console.log(e instanceof TypeError); // true + console.log(e.message); // "Coucou" + console.log(e.name); // "TypeError" + 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" } ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint16array/index.md b/files/fr/web/javascript/reference/global_objects/uint16array/index.md index c416de72726e4c..c9ae409149b07b 100644 --- a/files/fr/web/javascript/reference/global_objects/uint16array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint16array/index.md @@ -125,7 +125,7 @@ console.log(uint16.length); // 2 console.log(uint16.BYTES_PER_ELEMENT); // 2 // Construction à partir d'un tableau -var arr = new Uint16Array([21,31]); +var arr = new Uint16Array([21, 31]); console.log(arr[1]); // 31 // Construction à partir d'un tableau typé @@ -138,7 +138,9 @@ var buffer = new ArrayBuffer(8); var z = new Uint16Array(buffer, 0, 4); // Construction à partir d'un itérable -var iterable = function*(){ yield* [1,2,3]; }(); +var iterable = (function* () { + yield* [1, 2, 3]; +})(); var uint16 = new Uint16Array(iterable); // Uint16Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint16array/uint16array/index.md b/files/fr/web/javascript/reference/global_objects/uint16array/uint16array/index.md index 4b01d1f7d28e4c..ac999a7fdbf6d6 100644 --- a/files/fr/web/javascript/reference/global_objects/uint16array/uint16array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint16array/uint16array/index.md @@ -61,7 +61,7 @@ console.log(uint16.length); // 2 console.log(uint16.BYTES_PER_ELEMENT); // 2 // À partir d'un tableau -const arr = new Uint16Array([21,31]); +const arr = new Uint16Array([21, 31]); console.log(arr[1]); // 31 // À partir d'un autre tableau typé @@ -74,7 +74,9 @@ const buffer = new ArrayBuffer(8); const z = new Uint16Array(buffer, 0, 4); // À partir d'un itérable -const iterable = function*(){ yield* [1,2,3]; }(); +const iterable = (function* () { + yield* [1, 2, 3]; +})(); const uint16_from_iterable = new Uint16Array(iterable); // Uint16Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint32array/index.md b/files/fr/web/javascript/reference/global_objects/uint32array/index.md index 58095b6c3580b7..75ea4e65b2bfbb 100644 --- a/files/fr/web/javascript/reference/global_objects/uint32array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint32array/index.md @@ -125,7 +125,7 @@ console.log(uint32.length); // 2 console.log(uint32.BYTES_PER_ELEMENT); // 4 // Construction à partir d'un tableau -var arr = new Uint32Array([21,31]); +var arr = new Uint32Array([21, 31]); console.log(arr[1]); // 31 // Construction à partir d'un tableau typé @@ -138,7 +138,9 @@ var buffer = new ArrayBuffer(16); var z = new Uint32Array(buffer, 0, 4); // Construction à partir d'un itérable -var iterable = function*(){ yield* [1,2,3]; }(); +var iterable = (function* () { + yield* [1, 2, 3]; +})(); var uint32 = new Uint32Array(iterable); // Uint32Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint32array/uint32array/index.md b/files/fr/web/javascript/reference/global_objects/uint32array/uint32array/index.md index 7aededd9305c0e..aee214de1ed6e2 100644 --- a/files/fr/web/javascript/reference/global_objects/uint32array/uint32array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint32array/uint32array/index.md @@ -45,7 +45,7 @@ console.log(uint32.length); // 2 console.log(uint32.BYTES_PER_ELEMENT); // 4 // À partir d'un tableau -let arr = new Uint32Array([21,31]); +let arr = new Uint32Array([21, 31]); console.log(arr[1]); // 31 // À partir d'un autre tableau typé @@ -58,7 +58,9 @@ let buffer = new ArrayBuffer(16); let z = new Uint32Array(buffer, 0, 4); // À partir d'un itérable -let iterable = function*(){ yield* [1,2,3]; }(); +let iterable = (function* () { + yield* [1, 2, 3]; +})(); let uint32 = new Uint32Array(iterable); // Uint32Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint8array/index.md b/files/fr/web/javascript/reference/global_objects/uint8array/index.md index 746670d7e9742a..7121e1770c9a19 100644 --- a/files/fr/web/javascript/reference/global_objects/uint8array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint8array/index.md @@ -43,7 +43,7 @@ Le tableau typé **`Uint8Array`** représente un tableau d'entiers non signés, - [`Uint8Array.prototype.copyWithin()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) - : Copie une suite d'éléments d'un tableau dans le tableau. Voir également [`Array.prototype.copyWithin()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin). - [`Uint8Array.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/entries) - - : Renvoie un nouvel *itérateur de tableau* qui contient les paires clé/valeur pour chaque indice du tableau. Voir également [`Array.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/entries). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les paires clé/valeur pour chaque indice du tableau. Voir également [`Array.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/entries). - [`Uint8Array.prototype.every()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/every) - : Teste si l'ensemble des éléments du tableau remplissent une certaine condition donnée par une fonction de test. Voir également [`Array.prototype.every()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/every). - [`Uint8Array.prototype.fill()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill) @@ -63,7 +63,7 @@ Le tableau typé **`Uint8Array`** représente un tableau d'entiers non signés, - [`Uint8Array.prototype.join()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/join) - : Fusionne l'ensemble des éléments du tableau en une chaîne de caractères. Voir également [`Array.prototype.join()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/join). - [`Uint8Array.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/keys) - - : Renvoie un nouvel *itérateur de tableau* qui contient les clés de chaque indice du tableau. Voir également [`Array.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/keys). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les clés de chaque indice du tableau. Voir également [`Array.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/keys). - [`Uint8Array.prototype.lastIndexOf()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/lastIndexOf) - : Renvoie le dernier indice (le plus élevé) d'un élément du tableau qui est égal à la valeur fournie. Si aucun élément ne correspond, la valeur `-1` sera renvoyée. Voir également [`Array.prototype.lastIndexOf()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf). - [`Uint8Array.prototype.map()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) @@ -85,13 +85,13 @@ Le tableau typé **`Uint8Array`** représente un tableau d'entiers non signés, - [`Uint8Array.prototype.subarray()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) - : Renvoie un nouvel objet `Uint8Array` qui est le fragment du tableau courant, entre les indices de début et de fin donnés. - [`Uint8Array.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/values) - - : Renvoie un nouvel *itérateur de tableau* qui contient les valeurs correspondantes à chaque indice du tableau. Voir également [`Array.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/values). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les valeurs correspondantes à chaque indice du tableau. Voir également [`Array.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/values). - [`Uint8Array.prototype.toLocaleString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toLocaleString) - : Renvoie une chaîne de caractères localisée qui représente le tableau et ses éléments. Voir également [`Array.prototype.toLocaleString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString). - [`Uint8Array.prototype.toString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toString) - : Renvoie une chaîne de caractères qui représente le tableau et ses éléments. Voir également [`Array.prototype.toString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/toString). - [`Uint8Array.prototype[@@iterator]()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/@@iterator) - - : Renvoie un nouvel *itérateur de tableau* qui contient les valeurs correspondantes à chaque indice du tableau. + - : Renvoie un nouvel _itérateur de tableau_ qui contient les valeurs correspondantes à chaque indice du tableau. ## Exemples @@ -106,7 +106,7 @@ console.log(uint8.length); // 2 console.log(uint8.BYTES_PER_ELEMENT); // 1 // Construction à partir d'un tableau -let arr = new Uint8Array([21,31]); +let arr = new Uint8Array([21, 31]); console.log(arr[1]); // 31 // Construction à partir d'un tableau typé @@ -119,7 +119,9 @@ let buffer = new ArrayBuffer(8); let z = new Uint8Array(buffer, 1, 4); // Construction à partir d'un itérable -let iterable = function*(){ yield* [1,2,3]; }(); +let iterable = (function* () { + yield* [1, 2, 3]; +})(); let uint8 = new Uint8Array(iterable); // Uint8Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint8array/uint8array/index.md b/files/fr/web/javascript/reference/global_objects/uint8array/uint8array/index.md index b851d65961a798..df9941fa145b4e 100644 --- a/files/fr/web/javascript/reference/global_objects/uint8array/uint8array/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint8array/uint8array/index.md @@ -45,7 +45,7 @@ console.log(uint8.length); // 2 console.log(uint8.BYTES_PER_ELEMENT); // 1 // Construction à partir d'un tableau -let arr = new Uint8Array([21,31]); +let arr = new Uint8Array([21, 31]); console.log(arr[1]); // 31 // Construction à partir d'un tableau typé @@ -58,7 +58,9 @@ let buffer = new ArrayBuffer(8); let z = new Uint8Array(buffer, 1, 4); // Construction à partir d'un itérable -let iterable = function*(){ yield* [1,2,3]; }(); +let iterable = (function* () { + yield* [1, 2, 3]; +})(); let uint8 = new Uint8Array(iterable); // Uint8Array[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint8clampedarray/index.md b/files/fr/web/javascript/reference/global_objects/uint8clampedarray/index.md index 652d71a356cf59..2074c0aa897382 100644 --- a/files/fr/web/javascript/reference/global_objects/uint8clampedarray/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint8clampedarray/index.md @@ -43,7 +43,7 @@ Le tableau typé **`Uint8ClampedArray`** permet de représenter un tableau d'ent - [`Uint8ClampedArray.prototype.copyWithin()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) - : Copie une suite d'éléments d'un tableau dans le tableau. Voir également [`Array.prototype.copyWithin()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin). - [`Uint8ClampedArray.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/entries) - - : Renvoie un nouvel *itérateur de tableau* qui contient les paires clé/valeur pour chaque indice du tableau. Voir également [`Array.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/entries). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les paires clé/valeur pour chaque indice du tableau. Voir également [`Array.prototype.entries()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/entries). - [`Uint8ClampedArray.prototype.every()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/every) - : Teste si l'ensemble des éléments du tableau remplissent une certaine condition donnée par une fonction de test. Voir également [`Array.prototype.every()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/every). - [`Uint8ClampedArray.prototype.fill()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill) @@ -63,7 +63,7 @@ Le tableau typé **`Uint8ClampedArray`** permet de représenter un tableau d'ent - [`Uint8ClampedArray.prototype.join()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/join) - : Fusionne l'ensemble des éléments du tableau en une chaîne de caractères. Voir également [`Array.prototype.join()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/join). - [`Uint8ClampedArray.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/keys) - - : Renvoie un nouvel *itérateur de tableau* qui contient les clés de chaque indice du tableau. Voir également [`Array.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/keys). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les clés de chaque indice du tableau. Voir également [`Array.prototype.keys()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/keys). - [`Uint8ClampedArray.prototype.lastIndexOf()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/lastIndexOf) - : Renvoie le dernier indice (le plus élevé) d'un élément du tableau qui est égal à la valeur fournie. Si aucun élément ne correspond, la valeur `-1` sera renvoyée. Voir également [`Array.prototype.lastIndexOf()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf). - [`Uint8ClampedArray.prototype.map()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) @@ -85,13 +85,13 @@ Le tableau typé **`Uint8ClampedArray`** permet de représenter un tableau d'ent - [`Uint8ClampedArray.prototype.subarray()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) - : Renvoie un nouvel objet `Uint8ClampedArray` qui est le fragment du tableau courant, entre les indices de début et de fin donnés. - [`Uint8ClampedArray.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/values) - - : Renvoie un nouvel *itérateur de tableau* qui contient les valeurs correspondantes à chaque indice du tableau. Voir également [`Array.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/values). + - : Renvoie un nouvel _itérateur de tableau_ qui contient les valeurs correspondantes à chaque indice du tableau. Voir également [`Array.prototype.values()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/values). - [`Uint8ClampedArray.prototype.toLocaleString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toLocaleString) - : Renvoie une chaîne de caractères localisée qui représente le tableau et ses éléments. Voir également [`Array.prototype.toLocaleString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString). - [`Uint8ClampedArray.prototype.toString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toString) - : Renvoie une chaîne de caractères qui représente le tableau et ses éléments. Voir également [`Array.prototype.toString()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/toString). - [`Uint8ClampedArray.prototype[@@iterator]()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/@@iterator) - - : Renvoie un nouvel *itérateur de tableau* qui contient les valeurs correspondantes à chaque indice du tableau. + - : Renvoie un nouvel _itérateur de tableau_ qui contient les valeurs correspondantes à chaque indice du tableau. ## Exemples @@ -108,7 +108,7 @@ console.log(uintc8.length); // 2 console.log(uintc8.BYTES_PER_ELEMENT); // 1 // Construction à partir d'un tableau -let arr = new Uint8ClampedArray([21,31]); +let arr = new Uint8ClampedArray([21, 31]); console.log(arr[1]); // 31 // Construction à partir d'un autre TypedArray @@ -121,7 +121,9 @@ let buffer = new ArrayBuffer(8); let z = new Uint8ClampedArray(buffer, 1, 4); // Construction à partir d'un itérable -let iterable = function*(){ yield* [1,2,3]; }(); +let iterable = (function* () { + yield* [1, 2, 3]; +})(); let uintc8 = new Uint8ClampedArray(iterable); // Uint8ClampedArray[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/uint8clampedarray/uint8clampedarray/index.md b/files/fr/web/javascript/reference/global_objects/uint8clampedarray/uint8clampedarray/index.md index f76aacd728bc46..20b90f7085504f 100644 --- a/files/fr/web/javascript/reference/global_objects/uint8clampedarray/uint8clampedarray/index.md +++ b/files/fr/web/javascript/reference/global_objects/uint8clampedarray/uint8clampedarray/index.md @@ -47,7 +47,7 @@ console.log(uintc8.length); // 2 console.log(uintc8.BYTES_PER_ELEMENT); // 1 // À partir d'un tableau -let arr = new Uint8ClampedArray([21,31]); +let arr = new Uint8ClampedArray([21, 31]); console.log(arr[1]); // 31 // À partir d'un autre tableau typé @@ -60,7 +60,9 @@ let buffer = new ArrayBuffer(8); let z = new Uint8ClampedArray(buffer, 1, 4); // À partir d'un itérable -let iterable = function*(){ yield* [1,2,3]; }(); +let iterable = (function* () { + yield* [1, 2, 3]; +})(); let uintc8 = new Uint8ClampedArray(iterable); // Uint8ClampedArray[1, 2, 3] ``` diff --git a/files/fr/web/javascript/reference/global_objects/undefined/index.md b/files/fr/web/javascript/reference/global_objects/undefined/index.md index 34c0c20e3bea0c..7f6f9fb4509c2a 100644 --- a/files/fr/web/javascript/reference/global_objects/undefined/index.md +++ b/files/fr/web/javascript/reference/global_objects/undefined/index.md @@ -15,12 +15,12 @@ La propriété globale **`undefined`** représente la valeur primitive [`undefin ## Syntaxe ```js -undefined +undefined; ``` ## Description -`undefined` est une propriété de *l'objet global*, c'est-à-dire qu'elle est accessible globalement. La valeur initiale d'`undefined` est la valeur primitive [`undefined`](/fr/docs/Glossary/undefined). +`undefined` est une propriété de _l'objet global_, c'est-à-dire qu'elle est accessible globalement. La valeur initiale d'`undefined` est la valeur primitive [`undefined`](/fr/docs/Glossary/undefined). Dans les navigateurs modernes (JavaScript 1.8.5 / Firefox 4+), d'après la spécification ECMAScript 5, `undefined` est une propriété non-configurable et non accessible en écriture. Si, toutefois, elle peut être modifiée dans l'environnement utilisé, il faut éviter de l'écraser. @@ -32,15 +32,15 @@ Une variable pour laquelle aucune valeur n'a été assignée sera de type `undef > // À NE PAS FAIRE > > // affiche "toto string" dans la console -> (function() { -> const undefined = 'toto'; -> console.log(undefined, typeof undefined); +> (function () { +> const undefined = "toto"; +> console.log(undefined, typeof undefined); > })(); > > // affiche "toto string" dans la console -> (function(undefined) { +> (function (undefined) { > console.log(undefined, typeof undefined); -> })('toto'); +> })("toto"); > ``` ## Exemples @@ -52,14 +52,13 @@ Il est possible d'utiliser `undefined` et les opérateurs stricts pour l'égalit ```js let x; if (x === undefined) { - // ces instructions seront exécutées -} -else { - // ces instructions ne seront pas exécutées + // ces instructions seront exécutées +} else { + // ces instructions ne seront pas exécutées } ``` -> **Note :** L'opérateur d'égalité stricte doit être utilisé ici plutôt que l'opérateur *d'égalité simple*. En effet, `x == undefined` vérifie également si `x` vaut `null`, tandis que l'égalité stricte ne le fait pas. `null` n'est pas équivalent à `undefined`. +> **Note :** L'opérateur d'égalité stricte doit être utilisé ici plutôt que l'opérateur _d'égalité simple_. En effet, `x == undefined` vérifie également si `x` vaut `null`, tandis que l'égalité stricte ne le fait pas. `null` n'est pas équivalent à `undefined`. > > Voir la page sur les [opérateurs de comparaison](/fr/docs/Web/JavaScript/Reference/Operators) pour plus de détails. @@ -69,8 +68,8 @@ L'opérateur [`typeof`](/fr/docs/Web/JavaScript/Reference/Operators/typeof) peut ```js let x; -if (typeof x === 'undefined') { - // ces instructions seront exécutées +if (typeof x === "undefined") { + // ces instructions seront exécutées } ``` @@ -78,21 +77,22 @@ Une des raisons pour utiliser l'opérateur [`typeof`](/fr/docs/Web/JavaScript/Re ```js // x n'a pas encore été défini -if (typeof x === 'undefined') { // donnera true sans erreur - // ces instructions seront exécutées +if (typeof x === "undefined") { + // donnera true sans erreur + // ces instructions seront exécutées } -if (x === undefined) { // déclenche une ReferenceError - +if (x === undefined) { + // déclenche une ReferenceError } ``` Il existe toutefois une autre alternative. Puisque JavaScript utilise la portée statique, on saura qu'une variable a été déclarée si elle est définie dans un contexte englobant. -La portée globale est rattachée à [l'objet global](/fr/docs/Web/JavaScript/Reference/Global_Objects/globalThis), alors on peut vérifier l'existence d'une variable dans le contexte global en examinant la présence d'une propriété sur *l'objet global* via l'opérateur [`in`](/fr/docs/Web/JavaScript/Reference/Operators/in). Par exemple : +La portée globale est rattachée à [l'objet global](/fr/docs/Web/JavaScript/Reference/Global_Objects/globalThis), alors on peut vérifier l'existence d'une variable dans le contexte global en examinant la présence d'une propriété sur _l'objet global_ via l'opérateur [`in`](/fr/docs/Web/JavaScript/Reference/Operators/in). Par exemple : ```js -if ('x' in window) { +if ("x" in window) { // ces instructions seront exécutées uniquement // si x est défini dans la portée globale } diff --git a/files/fr/web/javascript/reference/global_objects/unescape/index.md b/files/fr/web/javascript/reference/global_objects/unescape/index.md index 0c03368cedfe7c..3f80ca72f44425 100644 --- a/files/fr/web/javascript/reference/global_objects/unescape/index.md +++ b/files/fr/web/javascript/reference/global_objects/unescape/index.md @@ -18,7 +18,7 @@ La fonction dépréciée **`unescape()`** calcule une nouvelle chaîne de caract ## Syntaxe ```js -unescape(str) +unescape(str); ``` ### Paramètres @@ -37,9 +37,9 @@ La fonction `unescape` est une propriété de l'_objet global_. ## Exemples ```js -unescape("abc123"); // "abc123" -unescape("%E4%F6%FC"); // "äöü" -unescape("%u0107"); // "ć" +unescape("abc123"); // "abc123" +unescape("%E4%F6%FC"); // "äöü" +unescape("%u0107"); // "ć" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/urierror/index.md b/files/fr/web/javascript/reference/global_objects/urierror/index.md index 3fc5a8c4d7b454..1e634a39d67344 100644 --- a/files/fr/web/javascript/reference/global_objects/urierror/index.md +++ b/files/fr/web/javascript/reference/global_objects/urierror/index.md @@ -34,15 +34,15 @@ L'objet **`URIError`** représente une erreur renvoyée lorsqu'une fonction de m ```js try { - decodeURIComponent('%') + decodeURIComponent("%"); } catch (e) { - console.log(e instanceof URIError) // true - console.log(e.message) // "malformed URI sequence" - console.log(e.name) // "URIError" - console.log(e.fileName) // "Scratchpad/1" - console.log(e.lineNumber) // 2 - console.log(e.columnNumber) // 2 - console.log(e.stack) // "@Scratchpad/2:2:3\n" + console.log(e instanceof URIError); // true + console.log(e.message); // "malformed URI sequence" + console.log(e.name); // "URIError" + console.log(e.fileName); // "Scratchpad/1" + console.log(e.lineNumber); // 2 + console.log(e.columnNumber); // 2 + console.log(e.stack); // "@Scratchpad/2:2:3\n" } ``` @@ -50,15 +50,15 @@ try { ```js try { - throw new URIError('Coucou', 'unFichier.js', 10) + throw new URIError("Coucou", "unFichier.js", 10); } catch (e) { - console.log(e instanceof URIError) // true - console.log(e.message) // "Coucou" - console.log(e.name) // "URIError" - 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" + console.log(e instanceof URIError); // true + console.log(e.message); // "Coucou" + console.log(e.name); // "URIError" + 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" } ``` diff --git a/files/fr/web/javascript/reference/global_objects/urierror/urierror/index.md b/files/fr/web/javascript/reference/global_objects/urierror/urierror/index.md index 90a6ec2afcdaa3..ba655578570074 100644 --- a/files/fr/web/javascript/reference/global_objects/urierror/urierror/index.md +++ b/files/fr/web/javascript/reference/global_objects/urierror/urierror/index.md @@ -11,10 +11,10 @@ Le constructeur **`URIError()`** permet de créer une erreur lorsqu'une fonction ## Syntaxe ```js -new URIError() -new URIError(message) -new URIError(message, fileName) -new URIError(message, fileName, lineNumber) +new URIError(); +new URIError(message); +new URIError(message, fileName); +new URIError(message, fileName, lineNumber); ``` ### Paramètres @@ -32,15 +32,15 @@ new URIError(message, fileName, lineNumber) ```js try { - decodeURIComponent('%') + decodeURIComponent("%"); } catch (e) { - console.log(e instanceof URIError) // true - console.log(e.message) // "malformed URI sequence" - console.log(e.name) // "URIError" - console.log(e.fileName) // "Scratchpad/1" - console.log(e.lineNumber) // 2 - console.log(e.columnNumber) // 2 - console.log(e.stack) // "@Scratchpad/2:2:3\n" + console.log(e instanceof URIError); // true + console.log(e.message); // "malformed URI sequence" + console.log(e.name); // "URIError" + console.log(e.fileName); // "Scratchpad/1" + console.log(e.lineNumber); // 2 + console.log(e.columnNumber); // 2 + console.log(e.stack); // "@Scratchpad/2:2:3\n" } ``` @@ -48,15 +48,15 @@ try { ```js try { - throw new URIError('Coucou', 'unFichier.js', 10) + throw new URIError("Coucou", "unFichier.js", 10); } catch (e) { - console.log(e instanceof URIError) // true - console.log(e.message) // "Coucou" - console.log(e.name) // "URIError" - 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" + console.log(e instanceof URIError); // true + console.log(e.message); // "Coucou" + console.log(e.name); // "URIError" + 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" } ``` diff --git a/files/fr/web/javascript/reference/global_objects/weakmap/delete/index.md b/files/fr/web/javascript/reference/global_objects/weakmap/delete/index.md index 20f322f4c5cd72..666d1550081ede 100644 --- a/files/fr/web/javascript/reference/global_objects/weakmap/delete/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakmap/delete/index.md @@ -33,7 +33,7 @@ wm.set(window, "toto"); wm.delete(window); // Renvoie true. La suppression a bien eu lieu. -wm.has(window); // Renvoie false. L'objet window n'est plus dans la WeakMap. +wm.has(window); // Renvoie false. L'objet window n'est plus dans la WeakMap. ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/weakmap/get/index.md b/files/fr/web/javascript/reference/global_objects/weakmap/get/index.md index 87147b8d670c70..7c366e386a82fa 100644 --- a/files/fr/web/javascript/reference/global_objects/weakmap/get/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakmap/get/index.md @@ -32,7 +32,7 @@ var wm = new WeakMap(); wm.set(window, "toto"); wm.get(window); // Renvoie "toto" -wm.get("machin"); // Renvoie undefined. +wm.get("machin"); // Renvoie undefined. ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/weakmap/has/index.md b/files/fr/web/javascript/reference/global_objects/weakmap/has/index.md index 04ddf2068e5b7f..e0cb11aa3841c7 100644 --- a/files/fr/web/javascript/reference/global_objects/weakmap/has/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakmap/has/index.md @@ -32,7 +32,7 @@ var wm = new WeakMap(); wm.set(window, "toto"); wm.has(window); // renvoie true -wm.has("machin"); // renvoie false +wm.has("machin"); // renvoie false ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/weakmap/index.md b/files/fr/web/javascript/reference/global_objects/weakmap/index.md index 6d7141490925c6..813af9d3f8242f 100644 --- a/files/fr/web/javascript/reference/global_objects/weakmap/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakmap/index.md @@ -52,11 +52,11 @@ Grâce aux objets natifs `WeakMap`, les références vers les clés sont faibles ```js var wm1 = new WeakMap(), - wm2 = new WeakMap(), - wm3 = new WeakMap(); + wm2 = new WeakMap(), + wm3 = new WeakMap(); var o1 = {}, - o2 = function(){}, - o3 = window; + o2 = function () {}, + o3 = window; wm1.set(o1, 37); wm1.set(o2, "azerty"); @@ -75,9 +75,9 @@ wm2.has(o3); // true (même si la valeur est 'undefined') wm3.set(o1, 37); wm3.get(o1); // 37 -wm1.has(o1); // true +wm1.has(o1); // true wm1.delete(o1); -wm1.has(o1); // false +wm1.has(o1); // false ``` ### Implémenter une classe semblable à `WeakMap` avec une méthode .clear() @@ -85,23 +85,23 @@ wm1.has(o1); // false ```js class ClearableWeakMap { constructor(init) { - this._wm = new WeakMap(init) + this._wm = new WeakMap(init); } clear() { - this._wm = new WeakMap() + this._wm = new WeakMap(); } delete(k) { - return this._wm.delete(k) + return this._wm.delete(k); } get(k) { - return this._wm.get(k) + return this._wm.get(k); } has(k) { - return this._wm.has(k) + return this._wm.has(k); } set(k, v) { - this._wm.set(k, v) - return this + this._wm.set(k, v); + return this; } } ``` @@ -116,7 +116,7 @@ class ClearableWeakMap { ## Voir aussi -- Une prothèse (*polyfill*) de `WeakMap` est disponible dans [`core-js`](https://github.com/zloirock/core-js#weakmap) +- Une prothèse (_polyfill_) de `WeakMap` est disponible dans [`core-js`](https://github.com/zloirock/core-js#weakmap) - [Le guide sur les collections à clé JavaScript](/fr/docs/Web/JavaScript/Guide/Keyed_collections) - [Masquer des détails d'implémentation avec les WeakMaps ECMAScript 2015](https://fitzgeraldnick.com/weblog/53/) (en anglais) - [`Map`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Map) diff --git a/files/fr/web/javascript/reference/global_objects/weakmap/weakmap/index.md b/files/fr/web/javascript/reference/global_objects/weakmap/weakmap/index.md index 2dc681e5f1bb9c..15bd28079dae83 100644 --- a/files/fr/web/javascript/reference/global_objects/weakmap/weakmap/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakmap/weakmap/index.md @@ -11,8 +11,8 @@ Le **constructeur `WeakMap()`** permet de créer un nouvel objet [`WeakMap`](/fr ## Syntaxe ```js -new WeakMap() -new WeakMap(iterable) +new WeakMap(); +new WeakMap(iterable); ``` ### Paramètres @@ -30,11 +30,11 @@ const wm2 = new WeakMap(); const wm3 = new WeakMap(); const o1 = {}; -const o2 = function() {}; +const o2 = function () {}; const o3 = window; wm1.set(o1, 37); -wm1.set(o2, 'azerty'); +wm1.set(o2, "azerty"); wm2.set(o1, o2); // une valeur peut être de n'importe quel type (objet ou fonction) wm2.set(o3, undefined); wm2.set(wm1, wm2); // les clés et les valeurs peuvent être des objets, même des WeakMaps diff --git a/files/fr/web/javascript/reference/global_objects/weakref/deref/index.md b/files/fr/web/javascript/reference/global_objects/weakref/deref/index.md index ecead3b6224140..ec691d61ff9cbb 100644 --- a/files/fr/web/javascript/reference/global_objects/weakref/deref/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakref/deref/index.md @@ -11,7 +11,7 @@ La méthode `deref` renvoie l'objet cible associé à l'objet [`WeakRef`](/fr/do ## Syntaxe ```js -deref() +deref(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/weakref/index.md b/files/fr/web/javascript/reference/global_objects/weakref/index.md index aadacb20fa33f6..60040dbf550b1a 100644 --- a/files/fr/web/javascript/reference/global_objects/weakref/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakref/index.md @@ -30,7 +30,7 @@ Une utilisation correcte de `WeakRef` nécessite une réflexion suffisante et il Voici quelques sujets spécifiques inclus dans [le document explicatif de la proposition correspondante](https://github.com/tc39/proposal-weakrefs/blob/master/reference.md) : -> [Les ramasses-miettes](https://fr.wikipedia.org/wiki/Ramasse-miettes_(informatique)) sont compliqués. Si une application ou une bibliothèque dépend d'un ramasse-miettes nettoyant un registre FinalizationRegistry ou appelant un finaliseur de façon précise et prédictible, qu'elle se prépare à être déçue : le nettoyage pourra avoir lieu bien plus tard que prévu voire pas du tout. Ce comportement grandement variable est dû : +> [Les ramasses-miettes]() sont compliqués. Si une application ou une bibliothèque dépend d'un ramasse-miettes nettoyant un registre FinalizationRegistry ou appelant un finaliseur de façon précise et prédictible, qu'elle se prépare à être déçue : le nettoyage pourra avoir lieu bien plus tard que prévu voire pas du tout. Ce comportement grandement variable est dû : > > - Au fait qu'un objet peut être récupéré par le ramasse-miettes bien plus tôt qu'un autre, même s'il devient inaccessible au même temps, par exemple en raison du ramassage générationnel. > - À l'action du ramasse-miettes qui peut être divisée dans le temps en utilisant des techniques incrémentales et concurrentes. diff --git a/files/fr/web/javascript/reference/global_objects/weakset/delete/index.md b/files/fr/web/javascript/reference/global_objects/weakset/delete/index.md index 31307010fad0d9..bd8edf18f34e5c 100644 --- a/files/fr/web/javascript/reference/global_objects/weakset/delete/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakset/delete/index.md @@ -33,10 +33,10 @@ var obj = {}; ws.add(window); -ws.delete(obj); // Renvoie false. Aucun objet obj n'a été trouvé ni retiré. +ws.delete(obj); // Renvoie false. Aucun objet obj n'a été trouvé ni retiré. ws.delete(window); // Renvoie true, l'objet window a pu être retiré. -ws.has(window); // Renvoie false, window n'appartient plus au WeakSet. +ws.has(window); // Renvoie false, window n'appartient plus au WeakSet. ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/weakset/has/index.md b/files/fr/web/javascript/reference/global_objects/weakset/has/index.md index 072c5015cf7b52..97ce9e59e5c655 100644 --- a/files/fr/web/javascript/reference/global_objects/weakset/has/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakset/has/index.md @@ -33,8 +33,8 @@ var ws = new WeakSet(); var obj = {}; ws.add(window); -mySet.has(window); // renvoie true -mySet.has(obj); // renvoie false +mySet.has(window); // renvoie true +mySet.has(obj); // renvoie false ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/weakset/index.md b/files/fr/web/javascript/reference/global_objects/weakset/index.md index 507661fbfd6413..48c7a34795bbe6 100644 --- a/files/fr/web/javascript/reference/global_objects/weakset/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakset/index.md @@ -25,31 +25,28 @@ Les fonctions récursives doivent faire attention aux structures de données cir ```js // Appeler un callback sur ce qui est stocké dans un objet -function execRecursively(fn, subject, _refs = null){ - if(!_refs) - _refs = new WeakSet(); +function execRecursively(fn, subject, _refs = null) { + if (!_refs) _refs = new WeakSet(); // On évite une récursion infinie - if(_refs.has(subject)) - return; + if (_refs.has(subject)) return; fn(subject); - if("object" === typeof subject){ + if ("object" === typeof subject) { _refs.add(subject); - for(let key in subject) - execRecursively(fn, subject[key], _refs); + for (let key in subject) execRecursively(fn, subject[key], _refs); } } const toto = { toto: "Toto", truc: { - truc: "Truc" - } + truc: "Truc", + }, }; toto.truc.machin = toto; // Référence circulaire ! -execRecursively(obj => console.log(obj), toto); +execRecursively((obj) => console.log(obj), toto); ``` Ici, on a un objet `WeakSet` qui est créé lors de la première exécution et qui est passé ensuite à chaque appel qui suit (via l'argument interne `_refs`). @@ -82,12 +79,12 @@ const truc = {}; ws.add(toto); ws.add(truc); -ws.has(toto); // true -ws.has(truc); // true +ws.has(toto); // true +ws.has(truc); // true ws.delete(toto); // retire toto de l'ensemble -ws.has(toto); // false, toto a été enlevé -ws.has(truc); // toujours true +ws.has(toto); // false, toto a été enlevé +ws.has(truc); // toujours true ``` On notera que `toto !== truc`. Bien que ce soient des objets similaires, ce ne sont pas _**les mêmes objets**_. Aussi, les deux sont ajoutés à l'ensemble. diff --git a/files/fr/web/javascript/reference/global_objects/weakset/weakset/index.md b/files/fr/web/javascript/reference/global_objects/weakset/weakset/index.md index 6f76a8ccd0c0f4..7fe3754d57a543 100644 --- a/files/fr/web/javascript/reference/global_objects/weakset/weakset/index.md +++ b/files/fr/web/javascript/reference/global_objects/weakset/weakset/index.md @@ -11,8 +11,8 @@ Le **constructeur `WeakSet()`** permet de créer des objets `WeakSet` qui stocke ## Syntaxe ```js -new WeakSet() -new WeakSet(iterable) +new WeakSet(); +new WeakSet(iterable); ``` ### Paramètres @@ -32,12 +32,12 @@ const truc = {}; ws.add(toto); ws.add(truc); -ws.has(toto); // true -ws.has(truc); // true +ws.has(toto); // true +ws.has(truc); // true ws.delete(toto); // retire toto de l'ensemble -ws.has(toto); // false, toto a été retiré -ws.has(truc); // true, truc est retenu +ws.has(toto); // false, toto a été retiré +ws.has(truc); // true, truc est retenu ``` On notera que `toto !== truc`. Même si ces objets se ressemblent, _ce ne sont pas **les mêmes objets**_. Aussi, ils sont tous les deux ajoutés à l'ensemble. diff --git a/files/fr/web/javascript/reference/iteration_protocols/index.md b/files/fr/web/javascript/reference/iteration_protocols/index.md index 69c9eadddf1856..9365305a104863 100644 --- a/files/fr/web/javascript/reference/iteration_protocols/index.md +++ b/files/fr/web/javascript/reference/iteration_protocols/index.md @@ -87,8 +87,8 @@ Certains itérateurs sont des itérables : var unTableau = [1, 5, 7]; var élémentsDuTableau = unTableau.entries(); -élémentsDuTableau.toString(); // "[object Array Iterator]" -élémentsDuTableau === élémentsDuTableau[Symbol.iterator](); // true +élémentsDuTableau.toString(); // "[object Array Iterator]" +élémentsDuTableau === élémentsDuTableau[Symbol.iterator](); // true ``` ## Exemples d'utilisation des protocoles d'itération @@ -97,38 +97,39 @@ Une {{jsxref("String")}} est un exemple d'objet natif itérable : ```js var uneChaîne = "coucou"; -typeof uneChaîne[Symbol.iterator]; // "function" +typeof uneChaîne[Symbol.iterator]; // "function" ``` [L'itérateur par défaut d'un objet `String`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/String/@@iterator) renverra les caractères de la chaîne les uns à la suite des autres : ```js var itérateur = uneChaîne[Symbol.iterator](); -itérateur + ""; // "[object String Iterator]" - -itérateur.next(); // { value: "c", done: false } -itérateur.next(); // { value: "o", done: false } -itérateur.next(); // { value: "u", done: false } -itérateur.next(); // { value: "c", done: false } -itérateur.next(); // { value: "o", done: false } -itérateur.next(); // { value: "u", done: false } -itérateur.next(); // { value: undefined, done: true } +itérateur + ""; // "[object String Iterator]" + +itérateur.next(); // { value: "c", done: false } +itérateur.next(); // { value: "o", done: false } +itérateur.next(); // { value: "u", done: false } +itérateur.next(); // { value: "c", done: false } +itérateur.next(); // { value: "o", done: false } +itérateur.next(); // { value: "u", done: false } +itérateur.next(); // { value: undefined, done: true } ``` Certains éléments natifs du langage, tels que [la syntaxe de décomposition](/fr/docs/Web/JavaScript/Reference/Opérateurs/Opérateur_de_décomposition), utilisent ce même protocole : ```js -[...uneChaîne]; // ["c", "o", "u", "c", "o", "u"] +[...uneChaîne]; // ["c", "o", "u", "c", "o", "u"] ``` Il est possible de redéfinir le comportement par défaut en définissant soi-même le symbole `@@iterator` : ```js -var uneChaîne = new String("yo"); // on construit un objet String explicitement afin d'éviter la conversion automatique +var uneChaîne = new String("yo"); // on construit un objet String explicitement afin d'éviter la conversion automatique -uneChaîne[Symbol.iterator] = function() { - return { // l'objet itérateur qui renvoie un seul élément, la chaîne "bop" - next: function() { +uneChaîne[Symbol.iterator] = function () { + return { + // l'objet itérateur qui renvoie un seul élément, la chaîne "bop" + next: function () { if (this._first) { this._first = false; return { value: "bop", done: false }; @@ -136,7 +137,7 @@ uneChaîne[Symbol.iterator] = function() { return { done: true }; } }, - _first: true + _first: true, }; }; ``` @@ -144,8 +145,8 @@ uneChaîne[Symbol.iterator] = function() { On notera que redéfinir le symbole `@@iterator` affecte également le comportement des éléments du langage qui utilisent le protocole : ```js -[...uneChaîne]; // ["bop"] -uneChaîne + ""; // "yo" +[...uneChaîne]; // ["bop"] +uneChaîne + ""; // "yo" ``` ## Exemples d'itérables @@ -161,9 +162,9 @@ Il est possible de construire un itérable dans un script de la façon suivante ```js var monItérable = {}; monItérable[Symbol.iterator] = function* () { - yield 1; - yield 2; - yield 3; + yield 1; + yield 2; + yield 3; }; [...monItérable]; // [1, 2, 3] ``` @@ -174,15 +175,25 @@ Plusieurs API utilisent les itérables, par exemple : {{jsxref("Map", "Map([ité ```js var monObjet = {}; -new Map([[1,"a"],[2,"b"],[3,"c"]]).get(2); // "b" -new WeakMap([[{},"a"],[monObjet,"b"],[{},"c"]]).get(monObjet); // "b" -new Set([1, 2, 3]).has(3); // true -new Set("123").has("2"); // true -new WeakSet(function*() { +new Map([ + [1, "a"], + [2, "b"], + [3, "c"], +]).get(2); // "b" +new WeakMap([ + [{}, "a"], + [monObjet, "b"], + [{}, "c"], +]).get(monObjet); // "b" +new Set([1, 2, 3]).has(3); // true +new Set("123").has("2"); // true +new WeakSet( + (function* () { yield {}; yield monObjet; yield {}; -}()).has(monObjet); // true + })(), +).has(monObjet); // true ``` ainsi que {{jsxref("Promise.all", "Promise.all(itérable)")}}, {{jsxref("Promise.race", "Promise.race(itérable)")}}, {{jsxref("Array.from", "Array.from()")}} @@ -192,8 +203,8 @@ ainsi que {{jsxref("Promise.all", "Promise.all(itérable)")}}, {{jsxref("Promise Certains éléments du langage utilisent des itérables, par exemple : [`for..of`](/fr/docs/Web/JavaScript/Reference/Instructions/for...of), [la syntaxe de décomposition](/fr/docs/Web/JavaScript/Reference/Opérateurs/Opérateur_de_décomposition), [yield\*](/fr/docs/Web/JavaScript/Reference/Opérateurs/yield*), [l'affectation par décomposition](/fr/docs/Web/JavaScript/Reference/Opérateurs/Affecter_par_décomposition) : ```js -for(let value of ["a", "b", "c"]){ - console.log(value); +for (let value of ["a", "b", "c"]) { + console.log(value); } // "a" // "b" @@ -201,7 +212,7 @@ for(let value of ["a", "b", "c"]){ [..."abc"]; // ["a", "b", "c"] -function* gen(){ +function* gen() { yield* ["a", "b", "c"]; } @@ -226,36 +237,36 @@ itérableMalFormé[Symbol.iterator] = () => 1 ### Un itérateur simple ```js -function créerItérateur(tableau){ - var nextIndex = 0; - - return { - next: function(){ - return nextIndex < tableau.length ? - {value: tableau[nextIndex++], done: false} : - {done: true}; - } - } +function créerItérateur(tableau) { + var nextIndex = 0; + + return { + next: function () { + return nextIndex < tableau.length + ? { value: tableau[nextIndex++], done: false } + : { done: true }; + }, + }; } -var it = créerItérateur(['yo', 'ya']); +var it = créerItérateur(["yo", "ya"]); console.log(it.next().value); // 'yo' console.log(it.next().value); // 'ya' -console.log(it.next().done); // true +console.log(it.next().done); // true ``` ### Un itérateur infini ```js -function créateurID(){ - var index = 0; +function créateurID() { + var index = 0; - return { - next: function(){ - return {value: index++, done: false}; - } - }; + return { + next: function () { + return { value: index++, done: false }; + }, + }; } var it = créateurID(); @@ -269,24 +280,23 @@ console.log(it.next().value); // '2' ### Avec un générateur ```js -function* créerUnGénérateurSimple(tableau){ - var nextIndex = 0; +function* créerUnGénérateurSimple(tableau) { + var nextIndex = 0; - while(nextIndex < tableau.length){ - yield tableau[nextIndex++]; - } + while (nextIndex < tableau.length) { + yield tableau[nextIndex++]; + } } -var gen = créerUnGénérateurSimple(['yo', 'ya']); +var gen = créerUnGénérateurSimple(["yo", "ya"]); console.log(gen.next().value); // 'yo' console.log(gen.next().value); // 'ya' -console.log(gen.next().done); // true +console.log(gen.next().done); // true -function* créateurID(){ - var index = 0; - while(true) - yield index++; +function* créateurID() { + var index = 0; + while (true) yield index++; } var gen = créateurID(); @@ -309,23 +319,23 @@ class ClasseSimple { return { next: () => { if (this.index < this.data.length) { - return {value: this.data[this.index++], done: false}; + return { value: this.data[this.index++], done: false }; } else { this.index = 0; // En réinitialisant l'index, on peut // "reprendre" l'itérateure sans avoir // à gérer de mise à jour manuelle - return {done: true}; + return { done: true }; } - } + }, }; } } -const simple = new ClasseSimple([1,2,3,4,5]); +const simple = new ClasseSimple([1, 2, 3, 4, 5]); for (const val of simple) { - console.log(val); // '1' '2' '3' '4' '5' + console.log(val); // '1' '2' '3' '4' '5' } ``` diff --git a/files/fr/web/javascript/reference/lexical_grammar/index.md b/files/fr/web/javascript/reference/lexical_grammar/index.md index 3964141f48ded8..4ec4839e28ade8 100644 --- a/files/fr/web/javascript/reference/lexical_grammar/index.md +++ b/files/fr/web/javascript/reference/lexical_grammar/index.md @@ -14,9 +14,9 @@ Les caractères de contrôle n'ont aucune représentation visuelle mais sont uti | Point de code | Nom | Abréviation | Description | | ------------- | ------------------------------------------------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `U+200C` | Antiliant sans chasse (_zero width non-joiner_ en anglais) | \ | Placé entre des caractères pour empêcher qu'ils soient connectés par une ligature dans certaines langues ([Wikipédia](https://fr.wikipedia.org/wiki/Antiliant_sans_chasse)). | -| `U+200D` | Liant sans chasse (_zero width joiner_ en anglais) | \ | Placé entre des caractères qui ne seraient normalement pas connectés pour les afficher comme connectés dans certaines langues ([Wikipédia](https://fr.wikipedia.org/wiki/Liant_sans_chasse)). | -| `U+FEFF` | Indicateur d'ordre des octets (_byte order mark_ en anglais) | \ | Utilisé au début d'un script pour indiquer qu'il est en Unicode et quel est l'ordre des octets ([Wikipedia](https://fr.wikipedia.org/wiki/Indicateur_d%27ordre_des_octets)). | +| `U+200C` | Antiliant sans chasse (_zero width non-joiner_ en anglais) | \ | Placé entre des caractères pour empêcher qu'ils soient connectés par une ligature dans certaines langues ([Wikipédia](https://fr.wikipedia.org/wiki/Antiliant_sans_chasse)). | +| `U+200D` | Liant sans chasse (_zero width joiner_ en anglais) | \ | Placé entre des caractères qui ne seraient normalement pas connectés pour les afficher comme connectés dans certaines langues ([Wikipédia](https://fr.wikipedia.org/wiki/Liant_sans_chasse)). | +| `U+FEFF` | Indicateur d'ordre des octets (_byte order mark_ en anglais) | \ | Utilisé au début d'un script pour indiquer qu'il est en Unicode et quel est l'ordre des octets ([Wikipedia](https://fr.wikipedia.org/wiki/Indicateur_d%27ordre_des_octets)). | ## Blancs @@ -24,12 +24,12 @@ Les caractères d'espacement (blancs) sont utilisés pour des raisons de lisibil | Point de code | Nom | Abréviation | Description | Séquence d'échappement | | ------------- | -------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------ | ---------------------- | -| U+0009 | Tabulation (horizontale) | \ | Tabulation horizontale | \t | -| U+000B | Tabulation verticale | \ | Tabulation verticale | \v | -| U+000C | Caractère de saut de page (_form feed_ en anglais) | \ | Caractère de contrôle pour le saut de page ([Wikipédia](http://en.wikipedia.org/wiki/Page_break#Form_feed)). | \f | -| U+0020 | Espace sécable (_space_ en anglais) | \ | Espace sécable | | -| U+00A0 | Espace insécable (_no-break space_ en anglais) | \ | Espace insécable | | -| Autres | Autres caractères d'espaces Unicode | \ | [Espaces Unicode sur Wikipédia](http://en.wikipedia.org/wiki/Space_%28punctuation%29#Spaces_in_Unicode) | | +| U+0009 | Tabulation (horizontale) | \ | Tabulation horizontale | \t | +| U+000B | Tabulation verticale | \ | Tabulation verticale | \v | +| U+000C | Caractère de saut de page (_form feed_ en anglais) | \ | Caractère de contrôle pour le saut de page ([Wikipédia](http://en.wikipedia.org/wiki/Page_break#Form_feed)). | \f | +| U+0020 | Espace sécable (_space_ en anglais) | \ | Espace sécable | | +| U+00A0 | Espace insécable (_no-break space_ en anglais) | \ | Espace insécable | | +| Autres | Autres caractères d'espaces Unicode | \ | [Espaces Unicode sur Wikipédia](http://en.wikipedia.org/wiki/Space_%28punctuation%29#Spaces_in_Unicode) | | ## Terminateurs de lignes @@ -39,10 +39,10 @@ Seuls les points de code Unicode qui suivent sont traités comme des fins de lig | Point de code | Nom | Abréviation | Description | Séquence d'échappement | | ------------- | ------------------------ | ----------- | ---------------------------------------------------------------------------- | ---------------------- | -| U+000A | Nouvelle ligne | \ | Caractère de nouvelle ligne pour les systèmes UNIX. | \n | -| U+000D | Retour chariot | \ | Caractère de nouvelle ligne pour les systèmes Commodore et les premiers Mac. | \r | -| U+2028 | Séparateur de ligne | \ | [Wikipédia](https://fr.wikipedia.org/wiki/Fin_de_ligne) | | -| U+2029 | Séparateur de paragraphe | \ | [Wikipédia](https://fr.wikipedia.org/wiki/Fin_de_ligne) | | +| U+000A | Nouvelle ligne | \ | Caractère de nouvelle ligne pour les systèmes UNIX. | \n | +| U+000D | Retour chariot | \ | Caractère de nouvelle ligne pour les systèmes Commodore et les premiers Mac. | \r | +| U+2028 | Séparateur de ligne | \ | [Wikipédia](https://fr.wikipedia.org/wiki/Fin_de_ligne) | | +| U+2029 | Séparateur de paragraphe | \ | [Wikipédia](https://fr.wikipedia.org/wiki/Fin_de_ligne) | | ## Commentaires @@ -80,7 +80,7 @@ Mais également sur plusieurs lignes, comme ceci : ```js function comment() { - /* Ce commentaire s'étend sur plusieurs lignes. Il n'y a + /* Ce commentaire s'étend sur plusieurs lignes. Il n'y a pas besoin de clore le commentaire avant d'avoir fini. */ console.log("Hello world !"); @@ -226,7 +226,7 @@ function import() {} // Illégal. Voir aussi la page {{jsxref("null")}} pour plus d'informations. ```js -null +null; ``` ### Littéraux booléens @@ -234,8 +234,8 @@ null Voir aussi la page {{jsxref("Boolean")}} pour plus d'informations. ```js -true -false +true; +false; ``` ### Littéraux numériques @@ -243,13 +243,13 @@ false #### Décimaux ```js -1234567890 -42 +1234567890; +42; // Attention à l'utilisation de zéros en début : -0888 // 888 est compris comme décimal -0777 // est compris comme octal et égale 511 en décimal +0888; // 888 est compris comme décimal +0777; // est compris comme octal et égale 511 en décimal ``` Les littéraux décimaux peuvent commencer par un zéro (`0`) suivi d'un autre chiffre. Mais si tous les chiffres après le 0 sont (strictement) inférieurs à 8, le nombre sera analysé comme un nombre octal. Cela n'entraînera pas d'erreur JavaScript, voir [bug Firefox 957513](https://bugzil.la/957513). Voir aussi la page sur {{jsxref("parseInt", "parseInt()")}}. @@ -259,9 +259,9 @@ Les littéraux décimaux peuvent commencer par un zéro (`0`) suivi d'un autre c La représentation binaire des nombres peut être utilisée avec une syntaxe qui comporte un zéro (0) suivi par le caractère latin "B" (minuscule ou majuscule) (`0b` ou `0B`). Cette syntaxe est apparue avec ECMAScript 2015 et il faut donc faire attention au tableau de compatibilité pour cette fonctionnalité. Si les chiffres qui composent le nombre ne sont pas 0 ou 1, cela entraînera une erreur {{jsxref("SyntaxError")}} : "Missing binary digits after 0b". ```js -var FLT_SIGNBIT = 0b10000000000000000000000000000000; // 2147483648 +var FLT_SIGNBIT = 0b10000000000000000000000000000000; // 2147483648 var FLT_EXPONENT = 0b01111111100000000000000000000000; // 2139095040 -var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607 +var FLT_MANTISSA = 0b00000000011111111111111111111111; // 8388607 ``` #### Octaux @@ -269,12 +269,12 @@ var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607 La syntaxe pour représenter des nombres sous forme octale est : un zéro (0), suivi par la lettre latine "O" (minuscule ou majuscule) (ce qui donne `0o` ou `0O)`. Cette syntaxe est apparue avec ECMAScript 2015 et il faut donc faire attention au tableau de compatibilité pour cette fonctionnalité. Si les chiffres qui composent le nombre ne sont pas compris entre 0 et 7, cela entraînera une erreur {{jsxref("SyntaxError")}} : "Missing octal digits after 0o". ```js -var n = 0O755; // 493 +var n = 0o755; // 493 var m = 0o644; // 420 // Aussi possible en utilisant des zéros en début du nombre (voir la note ci-avant) -0755 -0644 +0755; +0644; ``` #### Hexadécimaux @@ -282,9 +282,9 @@ var m = 0o644; // 420 Les littéraux hexadécimaux ont pour syntaxe : un zéro (0), suivi par la lettre latine "X" (minuscule ou majuscule) (ce qui donne `0x` ou `0X)`. Si les chiffres qui composent le nombre sont en dehors des unités hexadécimales (0123456789ABCDEF), cela entraînera une erreur {{jsxref("SyntaxError")}} : "Identifier starts immediately after numeric literal". ```js -0xFFFFFFFFFFFFFFFFF // 295147905179352830000 -0x123456789ABCDEF // 81985529216486900 -0XA // 10 +0xfffffffffffffffff; // 295147905179352830000 +0x123456789abcdef; // 81985529216486900 +0xa; // 10 ``` #### Littéraux `BigInt` @@ -308,8 +308,10 @@ Voir aussi les pages {{jsxref("Object")}} et {{jsxref("Opérateurs/Initialisateu var o = { a: "toto", b: "truc", c: 42 }; // notation raccourcie depuis ES6 -var a = "toto", b = "truc", c = 42; -var o = {a, b, c}; +var a = "toto", + b = "truc", + c = 42; +var o = { a, b, c }; // plutôt que var o = { a: a, b: b, c: c }; ``` @@ -319,7 +321,7 @@ var o = { a: a, b: b, c: c }; Voir aussi la page {{jsxref("Array")}} pour plus d'informations. ```js -[1954, 1974, 1990, 2014] +[1954, 1974, 1990, 2014]; ``` ### Littéraux de chaînes de caractères @@ -334,9 +336,9 @@ Avant la proposition consistant à rendre les chaînes JSON valides selon ECMA-2 Tous les codets peuvent être écrits sous la forme d'une séquence d'échappement. Les littéraux de chaînes de caractères sont évalués comme des valeurs `String` ECMAScript. Lorsque ces valeurs `String` sont générées, les codets Unicode sont encodés en UTF-16. -```js -'toto' -"truc" +```js-nolint +'toto'; +"truc"; ``` #### Séquence d'échappement hexadécimale @@ -344,7 +346,7 @@ Tous les codets peuvent être écrits sous la forme d'une séquence d'échappeme Une séquence d'échappement hexadécimale consiste en la succession de `\x` et de deux chiffres hexadécimaux représentant un codet sur l'intervalle 0x0000 à 0x00FF. ```js -'\xA9' // "©" +"\xA9"; // "©" ``` #### Séquence d'échappement Unicode @@ -354,7 +356,7 @@ La séquence d'échappement Unicode est composée de `\u` suivi de quatre chiffr Voir aussi {{jsxref("String.fromCharCode()")}} et {{jsxref("String.prototype.charCodeAt()")}}. ```js -'\u00A9' // "©" (U+A9) +"\u00A9"; // "©" (U+A9) ``` #### Échappement de points de code Unicode @@ -364,11 +366,11 @@ Apparu avec ECMAScript 2015, l'échappement de points de code Unicode permet d' Voir également {{jsxref("String.fromCodePoint()")}} et {{jsxref("String.prototype.codePointAt()")}}. ```js -'\u{2F804}' // CJK COMPATIBILITY IDEOGRAPH-2F804 (U+2F804) +"\u{2F804}"; // CJK COMPATIBILITY IDEOGRAPH-2F804 (U+2F804) // avec l'ancienne méthode d'échappement, cela aurait été écrit // avec une paire de surrogates -'\uD87E\uDC04' +"\uD87E\uDC04"; ``` ### Littéraux d'expressions rationnelles @@ -389,14 +391,14 @@ Voir la page [`RegExp`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/RegExp) Voir également la page sur [les gabarits de chaînes de caractères](/fr/docs/Web/JavaScript/Reference/Gabarit_chaînes_caractères) pour plus d'informations. ```js -`chaîne de caractères` +`chaîne de caractères`; `chaîne de caractères ligne 1 - chaîne de caractères ligne 2` + chaîne de caractères ligne 2`; -`chaîne1 ${expression} chaîne2` +`chaîne1 ${expression} chaîne2`; -tag `chaîne1 ${expression} chaîne2` +tag`chaîne1 ${expression} chaîne2`; ``` ## Insertion automatique de points-virgules @@ -426,8 +428,8 @@ La spécification ECMAScript mentionne [trois règles quant à l'insertion de po Ici `++` n'est pas traité comme [opérateur postfixe](/fr/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment) s'appliquant à la variable `b` car il y a un terminateur de ligne entre `b` et `++`. ```js -a = b -++c +a = b; +++c; // devient, après ASI : @@ -444,7 +446,7 @@ a = b; - `yield`, `yield*` - `module` -```js +```js-nolint return a + b diff --git a/files/fr/web/javascript/reference/operators/addition/index.md b/files/fr/web/javascript/reference/operators/addition/index.md index 3fc88aff27e184..d9214a9a7327bc 100644 --- a/files/fr/web/javascript/reference/operators/addition/index.md +++ b/files/fr/web/javascript/reference/operators/addition/index.md @@ -13,7 +13,7 @@ L'opérateur d'addition (`+`) produit la somme de deux opérandes numériques ou ## Syntaxe ```js -Opérateur : x + y +Opérateur: x + y; ``` ## Exemples @@ -22,26 +22,26 @@ Opérateur : x + y ```js // Number + Number -> addition -1 + 2 // 3 +1 + 2; // 3 // Boolean + Number -> addition -true + 1 // 2 +true + 1; // 2 // Boolean + Boolean -> addition -false + false // 0 +false + false; // 0 ``` ### Concaténation de chaînes de caractères ```js // String + String -> concatenation -'toto' + 'truc' // "tototruc" +"toto" + "truc"; // "tototruc" // Number + String -> concatenation -5 + 'toto' // "5toto" +5 + "toto"; // "5toto" // String + Boolean -> concatenation -'toto' + false // "totofalse" +"toto" + false; // "totofalse" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/operators/addition_assignment/index.md b/files/fr/web/javascript/reference/operators/addition_assignment/index.md index 352706970b91a1..aaa5870ba0cb82 100644 --- a/files/fr/web/javascript/reference/operators/addition_assignment/index.md +++ b/files/fr/web/javascript/reference/operators/addition_assignment/index.md @@ -12,8 +12,8 @@ L'opérateur d'addition et d'affectation (`+=`) calcule la somme ou la concatén ## Syntaxe ```js -Opérateur : x += y -Signification : x = x + y +Opérateur: x += y; +Signification: x = x + y; ``` ## Exemples @@ -35,13 +35,13 @@ machin += 1; // 2 machin += false; // 1 // nombre + chaîne de caractères -> concaténation -truc += 'toto'; // "5toto" +truc += "toto"; // "5toto" // chaîne de caractères + booléen -> concaténation -toto += false // "totofalse" +toto += false; // "totofalse" // chaîne de caractères + chaîne de caractères -> concaténation -toto += 'truc' // "tototruc" +toto += "truc"; // "tototruc" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/operators/assignment/index.md b/files/fr/web/javascript/reference/operators/assignment/index.md index 792951305b37e9..70da94145621dd 100644 --- a/files/fr/web/javascript/reference/operators/assignment/index.md +++ b/files/fr/web/javascript/reference/operators/assignment/index.md @@ -13,7 +13,7 @@ L'opérateur d'assignement simple (`=`) est utilisé pour définir la valeur d'u ## Syntaxe ```js -x = y +x = y; ``` ## Exemples diff --git a/files/fr/web/javascript/reference/operators/async_function/index.md b/files/fr/web/javascript/reference/operators/async_function/index.md index cc1f124e1777ec..40486457d94529 100644 --- a/files/fr/web/javascript/reference/operators/async_function/index.md +++ b/files/fr/web/javascript/reference/operators/async_function/index.md @@ -39,29 +39,30 @@ Une expression `async function` est très proche, et partage quasiment la même ```js function resolveAfter2Seconds(x) { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve(x); }, 2000); }); -}; +} -(async function(x) { // fonction asynchrone immédiatement appelée +(async function (x) { + // fonction asynchrone immédiatement appelée var a = resolveAfter2Seconds(20); var b = resolveAfter2Seconds(30); - return x + await a + await b; -})(10).then(v => { - console.log(v); // affiche 60 après 2 secondes. + return x + (await a) + (await b); +})(10).then((v) => { + console.log(v); // affiche 60 après 2 secondes. }); -var add = async function(x) { +var add = async function (x) { var a = await resolveAfter2Seconds(20); var b = await resolveAfter2Seconds(30); return x + a + b; }; -add(10).then(v => { - console.log(v); // affiche 60 après 4 secondes. +add(10).then((v) => { + console.log(v); // affiche 60 après 4 secondes. }); ``` diff --git a/files/fr/web/javascript/reference/operators/async_function_star_/index.md b/files/fr/web/javascript/reference/operators/async_function_star_/index.md index ad120173ba3fd4..929fcbd87153d1 100644 --- a/files/fr/web/javascript/reference/operators/async_function_star_/index.md +++ b/files/fr/web/javascript/reference/operators/async_function_star_/index.md @@ -58,7 +58,9 @@ L'exemple qui suit définit une fonction génératrice asynchrone anonyme et l'a const x = async function* (y) { yield Promise.resolve(y * y); }; -x(6).next().then((res) => console.log(res.value)); // affiche 36 +x(6) + .next() + .then((res) => console.log(res.value)); // affiche 36 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/operators/await/index.md b/files/fr/web/javascript/reference/operators/await/index.md index 91581d330891a9..53f65908885309 100644 --- a/files/fr/web/javascript/reference/operators/await/index.md +++ b/files/fr/web/javascript/reference/operators/await/index.md @@ -31,7 +31,7 @@ Si on passe une promesse à une expression `await`, celle-ci attendra jusqu'à l ```js function resolveAfter2Seconds(x) { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve(x); }, 2000); @@ -50,9 +50,9 @@ Les objets dotés d'une méthode `then()` (_thenable_ en anglais) seront égalem ```js async function f0() { const thenable = { - then: function(resolve, _reject) { + then: function (resolve, _reject) { resolve("résolu :)"); - } + }, }; console.log(await thenable); // résolu :) } @@ -85,11 +85,9 @@ f3(); On peut également gérer le cas où la promesse est rejetée grâce à {{jsxref("Promise.prototype.catch()")}} : ```js -var response = await maFonctionPromesse().catch( - (err) => { - console.log(err); - } -); +var response = await maFonctionPromesse().catch((err) => { + console.log(err); +}); ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/operators/bitwise_and/index.md b/files/fr/web/javascript/reference/operators/bitwise_and/index.md index 041b93797b38fd..e252aa9501fea5 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_and/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_and/index.md @@ -12,14 +12,14 @@ L'opérateur ET binaire (`&`) renvoie un nombre dont la représentation binaire ## Syntaxe ```js -a & b +a & b; ``` ## Description Les opérandes sont convertis en entiers sur 32 bits et exprimés comme une séquence de bits. Les nombres sur plus de 32 bits ont leurs bits en excès écartés. Par exemple, l'entier suivant nécessite plus de 32 bits pour être représenté et il sera converti en un entier sur 32 bits : -```js +```plain Avant: 11100110111110100000000000000110000000000001 Après: 10100000000000000110000000000001 ``` diff --git a/files/fr/web/javascript/reference/operators/bitwise_and_assignment/index.md b/files/fr/web/javascript/reference/operators/bitwise_and_assignment/index.md index 1b2543dd26769e..3754dc382d0410 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_and_assignment/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_and_assignment/index.md @@ -12,8 +12,8 @@ L'opérateur d'affectation après ET binaire (`&=`) utilise la représentation b ## Syntaxe ```js -Opérateur : x &= y -Signification : x = x & y +Opérateur: x &= y; +Signification: x = x & y; ``` ## Exemples diff --git a/files/fr/web/javascript/reference/operators/bitwise_not/index.md b/files/fr/web/javascript/reference/operators/bitwise_not/index.md index 3e13a1ce66f9a9..332a993170800c 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_not/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_not/index.md @@ -13,14 +13,14 @@ L'opérateur binaire NON (`~`) prend l'opposé de chaque bit de son opérande et ## Syntaxe ```js -~a +~a; ``` ## Description L'opérande est converti en un entier signé sur 32 bits. Les nombres avec plus de 32 bits voient leurs bits les plus significatifs être tronqués. Voici un exemple où l'entier qui suit est supérieur à une valeur pouvant être exprimée sur 32 bits : la conversion écrête la valeur pour obtenir un entier signé sur 32 bits : -```js +```plain Avant : 11100110111110100000000000000110000000000001 Après : 10100000000000000110000000000001 ``` @@ -52,9 +52,9 @@ Appliquer un NON binaire sur n'importe quel nombre `x` fournira la valeur `-(x + ### Utiliser le NON binaire ```js -~0; // -1 +~0; // -1 ~-1; // 0 -~1; // -2 +~1; // -2 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/operators/bitwise_or/index.md b/files/fr/web/javascript/reference/operators/bitwise_or/index.md index 91917f8f454cc4..4df872f29a4eb4 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_or/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_or/index.md @@ -12,14 +12,14 @@ L'opérateur OU binaire (`|`) renvoie un nombre dont la représentation binaire ## Syntaxe ```js -a | b +a | b; ``` ## Description Les opérandes sont convertis en entiers sur 32 bits et exprimés comme une séquence de bits. Les nombres sur plus de 32 bits ont leurs bits en excès écartés. Par exemple, l'entier suivant nécessite plus de 32 bits pour être représenté et il sera converti en un entier sur 32 bits : -```js +```plain Avant: 11100110111110100000000000000110000000000001 Après: 10100000000000000110000000000001 ``` @@ -35,7 +35,7 @@ La table de vérité pour l'opérateur OU est : | 1 | 0 | 1 | | 1 | 1 | 1 | -```js +```plain 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- diff --git a/files/fr/web/javascript/reference/operators/bitwise_or_assignment/index.md b/files/fr/web/javascript/reference/operators/bitwise_or_assignment/index.md index 54fcd267625a61..ebea8770fc8bac 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_or_assignment/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_or_assignment/index.md @@ -12,8 +12,8 @@ L'opérateur d'affectation après OU binaire (`|=`) utilise la représentation b ## Syntaxe ```js -Opérateur : x |= y -Signification : x = x | y +Opérateur: x |= y; +Signification: x = x | y; ``` ## Exemples diff --git a/files/fr/web/javascript/reference/operators/bitwise_xor/index.md b/files/fr/web/javascript/reference/operators/bitwise_xor/index.md index d750e5d3158411..1bc6c481c104a1 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_xor/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_xor/index.md @@ -12,14 +12,14 @@ L'opérateur binaire OU exclusif (XOR) (`^`) renvoie un nombre dont la représen ## Syntaxe ```js -a ^ b +a ^ b; ``` ## Description Les opérandes sont convertis en entiers sur 32 bits et exprimés comme une séquence de bits. Les nombres sur plus de 32 bits ont leurs bits en excès écartés. Par exemple, l'entier suivant nécessite plus de 32 bits pour être représenté et il sera converti en un entier sur 32 bits : -```js +```plain Avant: 11100110111110100000000000000110000000000001 Après: 10100000000000000110000000000001 ``` @@ -35,7 +35,7 @@ La table de vérité pour l'opérateur OU exclusif (XOR) est : | 1 | 0 | 1 | | 1 | 1 | 0 | -```js +```plain . 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- diff --git a/files/fr/web/javascript/reference/operators/bitwise_xor_assignment/index.md b/files/fr/web/javascript/reference/operators/bitwise_xor_assignment/index.md index ad9b41fc72b065..1d2d05e27fb62a 100644 --- a/files/fr/web/javascript/reference/operators/bitwise_xor_assignment/index.md +++ b/files/fr/web/javascript/reference/operators/bitwise_xor_assignment/index.md @@ -12,8 +12,8 @@ L'opérateur d'affectation après OU exclusif (XOR) binaire (`^=`) utilise la re ## Syntaxe ```js -Opérateur : x ^= y -Signification : x = x ^ y +Opérateur: x ^= y; +Signification: x = x ^ y; ``` ## Exemples @@ -21,14 +21,14 @@ Signification : x = x ^ y ### Utiliser l'affectation après OU exclusif binaire ```js -let a = 5; // 00000000000000000000000000000101 -a ^= 3; // 00000000000000000000000000000011 +let a = 5; // 00000000000000000000000000000101 +a ^= 3; // 00000000000000000000000000000011 console.log(a); // 00000000000000000000000000000110 // 6 -let b = 5; // 00000000000000000000000000000101 -b ^= 0; // 00000000000000000000000000000000 +let b = 5; // 00000000000000000000000000000101 +b ^= 0; // 00000000000000000000000000000000 console.log(b); // 00000000000000000000000000000101 // 5 diff --git a/files/fr/web/javascript/reference/operators/class/index.md b/files/fr/web/javascript/reference/operators/class/index.md index 427e4824832a69..fd36e9fe92e53f 100644 --- a/files/fr/web/javascript/reference/operators/class/index.md +++ b/files/fr/web/javascript/reference/operators/class/index.md @@ -54,12 +54,12 @@ var Toto = class TotoNommé { quiEstLa() { return TotoNommé.name; } -} +}; -var truc = new Toto; +var truc = new Toto(); truc.quiEstLa(); // "TotoNommmé" -TotoNommé.name; // ReferenceError -Toto.name; // "TotoNommé" +TotoNommé.name; // ReferenceError +Toto.name; // "TotoNommé" ``` ## Spécifications