aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/classes/private_class_fields
diff options
context:
space:
mode:
authorSphinxKnight <SphinxKnight@users.noreply.github.com>2022-03-16 17:52:18 +0100
committerGitHub <noreply@github.com>2022-03-16 17:52:18 +0100
commit500f444d23a7a758da229ebe6b9691cc5d4fe731 (patch)
treeca277561f7f3c5f2c9c3e80a895ac32f30852238 /files/fr/web/javascript/reference/classes/private_class_fields
parentde831e4687986c3a60b9ced69ce9faefda8df4b9 (diff)
downloadtranslated-content-500f444d23a7a758da229ebe6b9691cc5d4fe731.tar.gz
translated-content-500f444d23a7a758da229ebe6b9691cc5d4fe731.tar.bz2
translated-content-500f444d23a7a758da229ebe6b9691cc5d4fe731.zip
Fix #4269 - Removes empty/special characters (#4270)
* Remove ufeff * Remove u2064 * Remove u2062 * Replace u202f followed by : with &nbsp;: * Replace u202f next to « or » with &nbsp; and « or » * Replace u202f followed by ; with &nbsp;; * Replace u202f followed by ! with &nbsp; * Replace u202f followed by ? with &nbsp;? * Replace remaining u202f with classical space * Replace u200b surrounded by space with classical space * Replace u200b surrounded by space with classical space - again (repeated) * Remove remaining u200b * Remove u200a * Replace u2009 with &nbsp; * Remove u00ad * Replace u00a0 followed by : ! or ? with &nbsp; and punctuation * Replace u00a0 surrounded « or » with &nbsp; and punctuation * Replace u00a0 followed by whitespaces * Replace u00a0 preceded by whitespaces * Replace u00a0 followed by a newline with a newline * Replace u00a0 followed by a newline with a newline - Take2 * Replace u00a0 followed by a ; &nbsp; and punctuation * Remove u00a0 followed by , * Remove u00a0 in indentation spaces with \n([ ]*)([\u00a0])([ ]*) * Manual replacement of ([\u00a0])([ ]+) * Replace remaining ([\u00a0]+) by a space * cleaning empty elements * remove ufe0f * Remove u00a0 and u202f after merging against updated main * remove double whitespace using (\w)( )(\w)
Diffstat (limited to 'files/fr/web/javascript/reference/classes/private_class_fields')
-rw-r--r--files/fr/web/javascript/reference/classes/private_class_fields/index.md110
1 files changed, 55 insertions, 55 deletions
diff --git a/files/fr/web/javascript/reference/classes/private_class_fields/index.md b/files/fr/web/javascript/reference/classes/private_class_fields/index.md
index 45ad084074..7b6a0b1d73 100644
--- a/files/fr/web/javascript/reference/classes/private_class_fields/index.md
+++ b/files/fr/web/javascript/reference/classes/private_class_fields/index.md
@@ -35,12 +35,12 @@ La limitation des variables statiques ne pouvant être appelées que par des mé
```js
class ClassWithPrivateStaticField {
-  static #PRIVATE_STATIC_FIELD
+ static #PRIVATE_STATIC_FIELD
-  static publicStaticMethod() {
-    ClassWithPrivateStaticField.#PRIVATE_STATIC_FIELD = 42
-    return ClassWithPrivateStaticField.#PRIVATE_STATIC_FIELD
-  }
+ static publicStaticMethod() {
+ ClassWithPrivateStaticField.#PRIVATE_STATIC_FIELD = 42
+ return ClassWithPrivateStaticField.#PRIVATE_STATIC_FIELD
+ }
}
console.assert(ClassWithPrivateStaticField.publicStaticMethod() === 42)
@@ -54,12 +54,12 @@ Ceci peut conduire à un comportement inattendu lors de l'utilisation de **`this
```js
class BaseClassWithPrivateStaticField {
-  static #PRIVATE_STATIC_FIELD
+ static #PRIVATE_STATIC_FIELD
-  static basePublicStaticMethod() {
-    this.#PRIVATE_STATIC_FIELD = 42
-    return this.#PRIVATE_STATIC_FIELD
-  }
+ static basePublicStaticMethod() {
+ this.#PRIVATE_STATIC_FIELD = 42
+ return this.#PRIVATE_STATIC_FIELD
+ }
}
class SubClass extends BaseClassWithPrivateStaticField { }
@@ -75,18 +75,18 @@ console.assert(error instanceof TypeError)
### Champs d'instance privés
-Les champs d'instance privés sont déclarés avec des **noms** à **#** (prononcés "_noms à hash_", "_hash names_" en anglais), qui sont des identifieurs préfixés par `#`. Le `#` fait partie du nom lui-même. Il est utilisé tant pour la déclaration que pour l'accès.
+Les champs d'instance privés sont déclarés avec des **noms** à **#** (prononcés "_noms à hash_", "_hash names_" en anglais), qui sont des identifieurs préfixés par `#`. Le `#` fait partie du nom lui-même. Il est utilisé tant pour la déclaration que pour l'accès.
L'encapsulation est forcée par le langage. C'est une erreur de syntaxe que de faire référence aux noms à `#` en dehors de leur portée.
```js
class ClassWithPrivateField {
-  #privateField
+ #privateField
-  constructor() {
-    this.#privateField = 42
-    this.#randomField = 666 // Erreur de syntaxe
-  }
+ constructor() {
+ this.#privateField = 42
+ this.#randomField = 666 // Erreur de syntaxe
+ }
}
const instance = new ClassWithPrivateField()
@@ -103,17 +103,17 @@ Les méthodes statiques privées peuvent être des fonctions génératrices, asy
```js
class ClassWithPrivateStaticMethod {
-    static #privateStaticMethod() {
-        return 42
-    }
+ static #privateStaticMethod() {
+ return 42
+ }
-    static publicStaticMethod1() {
-        return ClassWithPrivateStaticMethod.#privateStaticMethod();
-    }
+ static publicStaticMethod1() {
+ return ClassWithPrivateStaticMethod.#privateStaticMethod();
+ }
-    static publicStaticMethod2() {
-       return this.#privateStaticMethod();
-  }
+ static publicStaticMethod2() {
+ return this.#privateStaticMethod();
+ }
}
console.assert(ClassWithPrivateStaticMethod.publicStaticMethod1() === 42);
@@ -124,15 +124,15 @@ Cela peut conduire à un comportement inattendu lors de l'utilisation de **`this
```js
class Base {
-    static #privateStaticMethod() {
-        return 42;
-    }
-    static publicStaticMethod1() {
-        return Base.#privateStaticMethod();
-    }
-    static publicStaticMethod2() {
-        return this.#privateStaticMethod();
-    }
+ static #privateStaticMethod() {
+ return 42;
+ }
+ static publicStaticMethod1() {
+ return Base.#privateStaticMethod();
+ }
+ static publicStaticMethod2() {
+ return this.#privateStaticMethod();
+ }
}
class Derived extends Base {}
@@ -147,41 +147,41 @@ Les méthodes d'instance privées sont des méthodes disponibles dans les instan
```js
class ClassWithPrivateMethod {
-  #privateMethod() {
-    return 'hello world'
-  }
+ #privateMethod() {
+ return 'hello world'
+ }
-  getPrivateMessage() {
-      return this.#privateMethod()
-  }
+ getPrivateMessage() {
+ return this.#privateMethod()
+ }
}
const instance = new ClassWithPrivateMethod()
console.log(instance.getPrivateMessage())
-// expected output: "hello worl​d"
+// expected output: "hello world"
```
Les méthodes d'instance privées peuvent être des fonctions génératrices, asynchones ou génératrices asynchrones. Des accesseurs (getters) et des mutateurs (setters) privés sont aussi posibles :
```js
class ClassWithPrivateAccessor {
-  #message
-
-  get #decoratedMessage() {
-    return `✨${this.#message}✨`
-  }
-  set #decoratedMessage(msg) {
-    this.#message = msg
-  }
-
-  constructor() {
-    this.#decoratedMessage = 'hello world'
-    console.log(this.#decoratedMessage)
-  }
+ #message
+
+ get #decoratedMessage() {
+ return `✨${this.#message}✨`
+ }
+ set #decoratedMessage(msg) {
+ this.#message = msg
+ }
+
+ constructor() {
+ this.#decoratedMessage = 'hello world'
+ console.log(this.#decoratedMessage)
+ }
}
new ClassWithPrivateAccessor();
-// expected output: "✨hello worl​d✨"
+// expected output: "✨hello world✨"
```
## Spécifications