issue139:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue139:c_c [2018/12/01 16:16] – créée auntiee | issue139:c_c [2018/12/07 15:00] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | I’ve recently begun using GatsbyJS (a static site/ | + | **I’ve recently begun using GatsbyJS (a static site/ |
- | What is ECMAScript? | + | J'ai récemment commencé à utiliser GatsbyJS (un générateur de site statique et d' |
- | It’s essentially a series of enhancements to traditional (“vanilla”) JavaScript. It’s intended to update faster and offer more quality-of-life features than normal JS. | + | **What is ECMAScript? |
+ | It’s essentially a series of enhancements to traditional (“vanilla”) JavaScript. It’s intended to update faster and offer more quality-of-life features than normal JS.** | ||
- | New Features | + | Qu' |
+ | |||
+ | C'est à la base une série d' | ||
+ | |||
+ | **New Features | ||
ES6 brought with it a large number of changes. | ES6 brought with it a large number of changes. | ||
Ligne 16: | Ligne 21: | ||
‘let’ defines a locally scoped variable that you can re-assign, but not redeclare. So if you want to make a counter that is run through a loop, ‘let’ would be what you want. | ‘let’ defines a locally scoped variable that you can re-assign, but not redeclare. So if you want to make a counter that is run through a loop, ‘let’ would be what you want. | ||
- | ‘const’ defines a locally scoped variable that cannot be changed once declared (it’s a constant variable, in other words). So if you want to scale various values by the same amount without the chance of it changing, use a const for the scaling value. | + | ‘const’ defines a locally scoped variable that cannot be changed once declared (it’s a constant variable, in other words). So if you want to scale various values by the same amount without the chance of it changing, use a const for the scaling value.** |
- | Spread | + | Nouvelles fonctionnalités |
+ | |||
+ | ES6 apporte avec lui un grand nombre de changements. | ||
+ | |||
+ | Let/Const | ||
+ | |||
+ | Dans le JS ordinaire, vous déclarez classiquement une var et vous en restez là. ES6 offre de nouvelles options - let et const. | ||
+ | |||
+ | « let » définit une variable locale que vous pouvez ré-assigner, | ||
+ | |||
+ | « const » définit une variable locale qui ne peut plus être changée une fois déclarée (c' | ||
+ | |||
+ | **Spread | ||
Have you ever had an array that you want to dump to the console, or otherwise just turn into separate elements? Spread does exactly that. It even lets you combine two arrays with minimal fuss. | Have you ever had an array that you want to dump to the console, or otherwise just turn into separate elements? Spread does exactly that. It even lets you combine two arrays with minimal fuss. | ||
Ligne 27: | Ligne 44: | ||
Previously, if you wanted to join strings together, you had to use a + operator. Now, ES6 will let you call them within a string using backticks and ${} variables. | Previously, if you wanted to join strings together, you had to use a + operator. Now, ES6 will let you call them within a string using backticks and ${} variables. | ||
+ | |||
+ | let welcome = `Hello ${username}, | ||
+ | |||
+ | Spread | ||
+ | |||
+ | N' | ||
+ | |||
+ | Les lignes ci-dessus sortiront un tableau avec tous les éléments combinés ensemble. Si vous étiez sur le point de lancer console.log(...fruits), | ||
+ | |||
+ | Template Literals (littérales modèles) | ||
+ | |||
+ | Auparavant, si vous vouliez regrouper des chaînes, vous deviez utiliser l' | ||
let welcome = `Hello ${username}, | let welcome = `Hello ${username}, | ||
- | Arrow Functions | + | **Arrow Functions |
ES6 also introduced arrow functions - these are essentially the same as regular functions, except the syntax is different. The upside to the syntax changes are that the whole declaration is shorter and easier to read. | ES6 also introduced arrow functions - these are essentially the same as regular functions, except the syntax is different. The upside to the syntax changes are that the whole declaration is shorter and easier to read. | ||
Ligne 45: | Ligne 74: | ||
(num1, num2) => return num1 + num2 | (num1, num2) => return num1 + num2 | ||
- | If you have more than one line in the body of the function, you will need to wrap the body in curly braces. See the next section for an example. | + | If you have more than one line in the body of the function, you will need to wrap the body in curly braces. See the next section for an example.** |
- | Default Function Parameters | + | Fonctions Flèche |
+ | |||
+ | ES6 introduit les fonctions Flèche : elles sont à la base identiques aux fonctions ordinaires, sauf que la syntaxe est différente. L' | ||
+ | |||
+ | En JS classique : | ||
+ | |||
+ | function (num1, num2) { | ||
+ | return num1 + num2 | ||
+ | } | ||
+ | |||
+ | Avec ES6 : | ||
+ | |||
+ | (num1, num2) => return num1 + num2 | ||
+ | |||
+ | Si vous voulez plus d'une ligne dans le corps de la fonction, vous devrez entourer le corps d' | ||
+ | |||
+ | **Default Function Parameters | ||
As surprising as it may seem, vanilla JS doesn’t let you define default values to your function parameters (see above). | As surprising as it may seem, vanilla JS doesn’t let you define default values to your function parameters (see above). | ||
Ligne 53: | Ligne 98: | ||
Extract Data from Arrays and Objects | Extract Data from Arrays and Objects | ||
- | ES6 also simplified pulling data from objects and arrays (shown below). | + | ES6 also simplified pulling data from objects and arrays (shown below).** |
- | Conclusion/ | + | Paramètres par défaut des fonctions |
+ | |||
+ | Aussi surprenant que ça paraisse, le JS standard ne vous laisse pas définir des valeurs par défaut pour les paramètres des fonctions (voir ci-dessus). | ||
+ | |||
+ | Extraire des données des tableaux et objets | ||
+ | |||
+ | ES6 simplifie aussi l' | ||
+ | |||
+ | **Conclusion/ | ||
There are a lot of other things ES6 allows you to do - such as defining objects faster, classes, and many others. So far, the items listed above are the ones I have most commonly used and seen in documentation. As a bit of homework - see if you can figure out the new shortened syntax for object literals in ES6. | There are a lot of other things ES6 allows you to do - such as defining objects faster, classes, and many others. So far, the items listed above are the ones I have most commonly used and seen in documentation. As a bit of homework - see if you can figure out the new shortened syntax for object literals in ES6. | ||
- | Do you think I missed an important feature? Then please let me know via email at lswest34+fcm@gmail.com. Similarly, anyone who has requests for articles or corrections to past ones should let me know at the address listed above. | + | Do you think I missed an important feature? Then please let me know via email at lswest34+fcm@gmail.com. Similarly, anyone who has requests for articles or corrections to past ones should let me know at the address listed above.** |
+ | Conclusion / Travail personnel | ||
- | Further Reading | + | Il y a une foule d' |
+ | |||
+ | Pensez-vous que j'ai oublié une fonctionnalité importante ? Alors, merci de le faire savoir par mail à lswest34+fcm@gmail.com. De même, tous ceux qui ont des demandes d' | ||
+ | |||
+ | |||
+ | **Further Reading | ||
https:// | https:// | ||
Ligne 68: | Ligne 127: | ||
https:// | https:// | ||
- | https:// | + | https:// |
+ | |||
+ | Pour aller plus loin | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// |
issue139/c_c.1543677375.txt.gz · Dernière modification : 2018/12/01 16:16 de auntiee