Prototype methods, objects without proto by TevaHenry · Pull Request #69 · javascript-tutorial/fr.javascript.info
@@ -1,13 +1,13 @@
The method can take all enumerable keys using `Object.keys` and output their list. La méthode peut prendre toutes les clés énumérables en utilisant `Object.keys` et afficher leur liste.
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. 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.
```js run *!* let dictionary = Object.create(null, { toString: { // define toString property value() { // the value is a function toString: { // définir la propriété toString value() { // la valeur est une fonction return Object.keys(this).join(); } }Expand All
@@ -17,15 +17,15 @@ let dictionary = Object.create(null, {
dictionary.apple = "Apple";
dictionary.__proto__ = "test";
// apple and __proto__ is in the loop // apple et __proto__ sont dans la boucle for(let key in dictionary) { alert(key); // "apple", then "__proto__" alert(key); // "apple", puis "__proto__" }
// comma-separated list of properties by toString // liste de propriétés séparées par des virgules par toString alert(dictionary); // "apple,__proto__" ```
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable. 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.
See the the chapter [](info:property-descriptors) for review. Voir le chapitre [](info:property-descriptors) pour revoir.
The method can take all enumerable keys using `Object.keys` and output their list. La méthode peut prendre toutes les clés énumérables en utilisant `Object.keys` et afficher leur liste.
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. 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.
```js run *!* let dictionary = Object.create(null, { toString: { // define toString property value() { // the value is a function toString: { // définir la propriété toString value() { // la valeur est une fonction return Object.keys(this).join(); } }
// apple and __proto__ is in the loop // apple et __proto__ sont dans la boucle for(let key in dictionary) { alert(key); // "apple", then "__proto__" alert(key); // "apple", puis "__proto__" }
// comma-separated list of properties by toString // liste de propriétés séparées par des virgules par toString alert(dictionary); // "apple,__proto__" ```
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable. 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.
See the the chapter [](info:property-descriptors) for review. Voir le chapitre [](info:property-descriptors) pour revoir.