Skip to content

Commit bc06045

Browse files
authored
Merge pull request #69 from TevaHenry/master
Prototype methods, objects without proto
2 parents 9feaffd + 570be62 commit bc06045

File tree

5 files changed

+94
-95
lines changed

5 files changed

+94
-95
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
The method can take all enumerable keys using `Object.keys` and output their list.
2+
La méthode peut prendre toutes les clés énumérables en utilisant `Object.keys` et afficher leur liste.
33

4-
To make `toString` non-enumerable, let's define it using a property descriptor. The syntax of `Object.create` allows us to provide an object with property descriptors as the second argument.
4+
Pour rendre `toString` non-énumérable, définissons-le à l'aide d'un descripteur de propriété. La syntaxe de `Object.create` nous permet de fournir un objet avec des descripteurs de propriété comme second argument.
55

66
```js run
77
*!*
88
let dictionary = Object.create(null, {
9-
toString: { // define toString property
10-
value() { // the value is a function
9+
toString: { // définir la propriété toString
10+
value() { // la valeur est une fonction
1111
return Object.keys(this).join();
1212
}
1313
}
@@ -17,15 +17,15 @@ let dictionary = Object.create(null, {
1717
dictionary.apple = "Apple";
1818
dictionary.__proto__ = "test";
1919

20-
// apple and __proto__ is in the loop
20+
// apple et __proto__ sont dans la boucle
2121
for(let key in dictionary) {
22-
alert(key); // "apple", then "__proto__"
22+
alert(key); // "apple", puis "__proto__"
2323
}
2424

25-
// comma-separated list of properties by toString
25+
// liste de propriétés séparées par des virgules par toString
2626
alert(dictionary); // "apple,__proto__"
2727
```
2828

29-
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable.
29+
Lorsque nous créons une propriété à l'aide d'un descripteur, ses indicateurs sont `false` par défaut. Donc, dans le code ci-dessus, `dictionary.toString` est non énumérable.
3030

31-
See the the chapter [](info:property-descriptors) for review.
31+
Voir le chapitre [](info:property-descriptors) pour revoir.

1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ importance: 5
22

33
---
44

5-
# Add toString to the dictionary
5+
# Ajouter toString au dictionnaire
66

7-
There's an object `dictionary`, created as `Object.create(null)`, to store any `key/value` pairs.
7+
Il existe un objet `dictionary`, créé en tant que `Object.create(null)`, pour stocker toutes les paires `clé/valeur`.
88

9-
Add method `dictionary.toString()` into it, that should return a comma-delimited list of keys. Your `toString` should not show up in `for..in` over the object.
9+
Ajoutez la méthode `dictionary.toString()`, qui devrait renvoyer une liste de clés délimitée par des virgules. Votre `toString` ne devrait pas apparaître dans la boucle `for..in` sur l'objet.
1010

11-
Here's how it should work:
11+
Voici comment cela devrait fonctionner:
1212

1313
```js
1414
let dictionary = Object.create(null);
1515

1616
*!*
17-
// your code to add dictionary.toString method
17+
// votre code pour ajouter la méthode dictionary.toString
1818
*/!*
1919

2020
// add some data
2121
dictionary.apple = "Apple";
22-
dictionary.__proto__ = "test"; // __proto__ is a regular property key here
22+
dictionary.__proto__ = "test"; // __proto__ est une clé de propriété régulière ici
2323

24-
// only apple and __proto__ are in the loop
24+
// seulement apple et __proto__ sont dans la boucle
2525
for(let key in dictionary) {
26-
alert(key); // "apple", then "__proto__"
26+
alert(key); // "apple", puis "__proto__"
2727
}
2828

29-
// your toString in action
29+
// votre toString en action
3030
alert(dictionary); // "apple,__proto__"
3131
```

1-js/08-prototypes/04-prototype-methods/3-compare-calls/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
The first call has `this == rabbit`, the other ones have `this` equal to `Rabbit.prototype`, because it's actually the object before the dot.
2+
Le premier appel a `this==rabbit`, les autres ont `this` égal à `Rabbit.prototype`, car il s'agit en fait de l'objet avant le point.
33

4-
So only the first call shows `Rabbit`, other ones show `undefined`:
4+
Ainsi, seul le premier appel indique `Rabbit`, les autres affichent` undefined`:
55

66
```js run
77
function Rabbit(name) {

1-js/08-prototypes/04-prototype-methods/3-compare-calls/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# The difference between calls
5+
# La différence entre les appels
66

7-
Let's create a new `rabbit` object:
7+
Créons un nouvel objet `rabbit`:
88

99
```js
1010
function Rabbit(name) {
@@ -17,7 +17,7 @@ Rabbit.prototype.sayHi = function() {
1717
let rabbit = new Rabbit("Rabbit");
1818
```
1919

20-
These calls do the same thing or not?
20+
Ces appels font la même chose ou pas?
2121

2222
```js
2323
rabbit.sayHi();

0 commit comments

Comments
 (0)