From be03e664d802aa1d9a06101c4a344d09b278dbe0 Mon Sep 17 00:00:00 2001 From: pasor1 <pasor1@gmail.com> Date: Fri, 8 Jan 2021 10:35:30 +0100 Subject: [PATCH 01/10] Arrow functions basics, first translation --- .../17-arrow-functions-basics/article.md | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index e0fb5bda5..1126a4849 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -1,16 +1,16 @@ -# Arrow functions, the basics +# Arrow functions, le basi -There's another very simple and concise syntax for creating functions, that's often better than Function Expressions. +Esiste un'altra sintassi molto semplice e concisa per creare funzioni e che spesso è migliore delle Function Expressions. -It's called "arrow functions", because it looks like this: +E' chiamata "arrow functions", perché si presenta in questo modo: ```js let func = (arg1, arg2, ...argN) => expression ``` -...This creates a function `func` that accepts arguments `arg1..argN`, then evaluates the `expression` on the right side with their use and returns its result. +Questo codice crea una funzione `func` che accetta gli argomenti `arg1..argN` e li utilizza per valutare `expression` e restituirne il risultato. -In other words, it's the shorter version of: +In altre parole è una versione abbreviata di: ```js let func = function(arg1, arg2, ...argN) { @@ -18,12 +18,12 @@ let func = function(arg1, arg2, ...argN) { }; ``` -Let's see a concrete example: +Vediamo un esempio concreto: ```js run let sum = (a, b) => a + b; -/* This arrow function is a shorter form of: +/* Questa arrow function è una versione abbreviata di: let sum = function(a, b) { return a + b; @@ -33,22 +33,22 @@ let sum = function(a, b) { alert( sum(1, 2) ); // 3 ``` -As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result. +Come puoi vedere `(a, b) => a + b` rappresenta una funzione che accetta due argomenti `a` e `b`. Al momento dell'esecuzione, questa valuta l'espressione `a + b` e restituisce il risultato. -- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter. +- Se abbiamo un solo argomento, le parentesi che racchiudono gli argomenti possono essere omesse, abbreviando ulteriormente il codice. - For example: + Ad esempio: ```js run *!* let double = n => n * 2; - // roughly the same as: let double = function(n) { return n * 2 } + // più o meno lo steso di: let double = function(n) { return n * 2 } */!* alert( double(3) ); // 6 ``` -- If there are no arguments, parentheses will be empty (but they should be present): +- Se non ci sono argomenti, le parentesi saranno vuote (ma devono essere presenti): ```js run let sayHi = () => alert("Hello!"); @@ -56,9 +56,9 @@ As you can, see `(a, b) => a + b` means a function that accepts two arguments na sayHi(); ``` -Arrow functions can be used in the same way as Function Expressions. +Le Arrow functions possono essere usate allo stesso modo delle Function Expressions. -For instance, to dynamically create a function: +Ad esempio, per creare dinamicamente una funzione: ```js run let age = prompt("What is your age?", 18); @@ -70,42 +70,45 @@ let welcome = (age < 18) ? welcome(); ``` -Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure. +Le Arrow functions possono apparire poco familiari e leggibili all'inizio, ma ciò cambia rapidamente man mano che gli occhi si abitueranno alla struttura. -They are very convenient for simple one-line actions, when we're just too lazy to write many words. +Esse sono molto comode per semplici azioni su una riga, se siamo troppo pigri per scrivere più parole. -## Multiline arrow functions +## Arrow functions su più linee -The examples above took arguments from the left of `=>` and evaluated the right-side expression with them. +Gli esempi precedenti hanno preso argomenti alla sinistra di "=>" e con essi hanno valutato l'espressione a destra. -Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them. +A volte abbiamo bisogno di qualcosa di un po' più complesso, come espressioni o dichiarazioni multiple. Anche questo è possibile, ma dovremo racchiuderle tra parentesi graffe ed usare un +non normale`return`. -Like this: +In questo modo: ```js run -let sum = (a, b) => { // the curly brace opens a multiline function +let sum = (a, b) => { // le parentesi graffe aprono una funzione multilinea let result = a + b; *!* - return result; // if we use curly braces, then we need an explicit "return" + return result; // se usiamo le parentesi graffe abbiamo bisogno di un esplicito "return" */!* }; alert( sum(1, 2) ); // 3 ``` -```smart header="More to come" -Here we praised arrow functions for brevity. But that's not all! +```smart header="Molto di più..." -Arrow functions have other interesting features. +Qui abbiamo presentato le arrow functions in breve, ma questo non è tutto! -To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>. +Le Arrow functions possiedono altre interessanti caratteristiche. -For now, we can already use arrow functions for one-line actions and callbacks. +Per studiarle approfonditamente dobbiamo prima conoscere qualche altro aspetto di JavaScript, quindi torneremo alle arrow functions più avanti, nel capitolo <info: funzioni-freccia>. + +Per ora possiamo già utilizzarle per azioni su una riga sola e per callbacks. ``` ## Summary -Arrow functions are handy for one-liners. They come in two flavors: +Le Arrow functions sono utili per azioni su una riga sola. Possono essere scritte in due modi: -1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result. -2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something. +1. Senza parentesi graffe: `(...args) => expression` -- la parte destra è un'espressione: la funzione la valuta e restituisce il risultato. +2. Con parentesi graffe: `(...args) => { body }` -- le parentesi ci permettono di scrivere comandi multipli all'interno della funzione, ma abbiamo bisogno di dichiarare esplicitamente +`return` affichè sia ritornato qualcosa. From 148d311fd962f91765d9c1f3d11ea9fca42cbc96 Mon Sep 17 00:00:00 2001 From: pasor1 <pasor1@gmail.com> Date: Fri, 8 Jan 2021 10:41:49 +0100 Subject: [PATCH 02/10] updated task.md --- .../17-arrow-functions-basics/1-rewrite-arrow/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md b/1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md index 577f0c322..0b3a4b6cc 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md @@ -1,7 +1,7 @@ -# Riscrivi con funzioni freccia +# Riscrivi usando le arrow functions -Rimpiazza le espressioni di funzione con funzioni freccia: +Sostituisci le function expressions con arrow functions: ```js run function ask(question, yes, no) { From ae0332dfcc25b6a07d53017134a66a451fe739d6 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:44:35 +0100 Subject: [PATCH 03/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index 1126a4849..ce1f0645b 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -56,7 +56,7 @@ Come puoi vedere `(a, b) => a + b` rappresenta una funzione che accetta due argo sayHi(); ``` -Le Arrow functions possono essere usate allo stesso modo delle Function Expressions. +Le arrow functions possono essere usate allo stesso modo delle Function Expressions. Ad esempio, per creare dinamicamente una funzione: From c11399cc0dbd978e7e722164d4479127a3ca4530 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:44:58 +0100 Subject: [PATCH 04/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index ce1f0645b..4088d6dc3 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -70,7 +70,7 @@ let welcome = (age < 18) ? welcome(); ``` -Le Arrow functions possono apparire poco familiari e leggibili all'inizio, ma ciò cambia rapidamente man mano che gli occhi si abitueranno alla struttura. +Le arrow functions possono apparire poco familiari e leggibili all'inizio, ma ciò cambia rapidamente man mano che gli occhi si abitueranno alla struttura. Esse sono molto comode per semplici azioni su una riga, se siamo troppo pigri per scrivere più parole. From 73a72da11a6dc7655fc5a2adc8becf07599c673f Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:45:11 +0100 Subject: [PATCH 05/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index 4088d6dc3..e4b29e8fa 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -98,7 +98,7 @@ alert( sum(1, 2) ); // 3 Qui abbiamo presentato le arrow functions in breve, ma questo non è tutto! -Le Arrow functions possiedono altre interessanti caratteristiche. +Le arrow functions possiedono altre interessanti caratteristiche. Per studiarle approfonditamente dobbiamo prima conoscere qualche altro aspetto di JavaScript, quindi torneremo alle arrow functions più avanti, nel capitolo <info: funzioni-freccia>. From 235fe673156075e2a6cfc8ae32b4c5a8baeb586e Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:45:22 +0100 Subject: [PATCH 06/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index e4b29e8fa..f96225407 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -107,7 +107,7 @@ Per ora possiamo già utilizzarle per azioni su una riga sola e per callbacks. ## Summary -Le Arrow functions sono utili per azioni su una riga sola. Possono essere scritte in due modi: +Le arrow functions sono utili per azioni su una riga sola. Possono essere scritte in due modi: 1. Senza parentesi graffe: `(...args) => expression` -- la parte destra è un'espressione: la funzione la valuta e restituisce il risultato. 2. Con parentesi graffe: `(...args) => { body }` -- le parentesi ci permettono di scrivere comandi multipli all'interno della funzione, ma abbiamo bisogno di dichiarare esplicitamente From 6483317879c533bc19684ae4ea2ce989d82c5e35 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:45:46 +0100 Subject: [PATCH 07/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index f96225407..ce0e04f3c 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -100,7 +100,7 @@ Qui abbiamo presentato le arrow functions in breve, ma questo non è tutto! Le arrow functions possiedono altre interessanti caratteristiche. -Per studiarle approfonditamente dobbiamo prima conoscere qualche altro aspetto di JavaScript, quindi torneremo alle arrow functions più avanti, nel capitolo <info: funzioni-freccia>. +Per studiarle approfonditamente dobbiamo prima conoscere qualche altro aspetto di JavaScript, quindi torneremo alle arrow functions più avanti, nel capitolo <info:arrow-functions>. Per ora possiamo già utilizzarle per azioni su una riga sola e per callbacks. ``` From be3202ee0688f358993c61a7d29a84b771503644 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:46:53 +0100 Subject: [PATCH 08/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index ce0e04f3c..3c651370f 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -78,7 +78,7 @@ Esse sono molto comode per semplici azioni su una riga, se siamo troppo pigri pe Gli esempi precedenti hanno preso argomenti alla sinistra di "=>" e con essi hanno valutato l'espressione a destra. -A volte abbiamo bisogno di qualcosa di un po' più complesso, come espressioni o dichiarazioni multiple. Anche questo è possibile, ma dovremo racchiuderle tra parentesi graffe ed usare un +A volte abbiamo bisogno di qualcosa di un po' più complesso, come espressioni o dichiarazioni multiple. Anche questo è possibile, ma dovremo racchiuderle tra parentesi graffe ed usare un normale return. non normale`return`. In questo modo: From 22c9514ac2271a37ddfe8dfdc6550e84a88b2910 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:47:01 +0100 Subject: [PATCH 09/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 1 - 1 file changed, 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index 3c651370f..9fdbfc61d 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -79,7 +79,6 @@ Esse sono molto comode per semplici azioni su una riga, se siamo troppo pigri pe Gli esempi precedenti hanno preso argomenti alla sinistra di "=>" e con essi hanno valutato l'espressione a destra. A volte abbiamo bisogno di qualcosa di un po' più complesso, come espressioni o dichiarazioni multiple. Anche questo è possibile, ma dovremo racchiuderle tra parentesi graffe ed usare un normale return. -non normale`return`. In questo modo: From ac0406ce8a857559f64be3fb41ea8cc0d23c6855 Mon Sep 17 00:00:00 2001 From: Simone Pasini <66781510+pasor1@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:47:18 +0100 Subject: [PATCH 10/10] Update 1-js/02-first-steps/17-arrow-functions-basics/article.md Co-authored-by: Andrea <45577511+longo-andrea@users.noreply.github.com> --- 1-js/02-first-steps/17-arrow-functions-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/17-arrow-functions-basics/article.md b/1-js/02-first-steps/17-arrow-functions-basics/article.md index 9fdbfc61d..5e39932a5 100644 --- a/1-js/02-first-steps/17-arrow-functions-basics/article.md +++ b/1-js/02-first-steps/17-arrow-functions-basics/article.md @@ -110,4 +110,4 @@ Le arrow functions sono utili per azioni su una riga sola. Possono essere scritt 1. Senza parentesi graffe: `(...args) => expression` -- la parte destra è un'espressione: la funzione la valuta e restituisce il risultato. 2. Con parentesi graffe: `(...args) => { body }` -- le parentesi ci permettono di scrivere comandi multipli all'interno della funzione, ma abbiamo bisogno di dichiarare esplicitamente -`return` affichè sia ritornato qualcosa. +`return` affinché sia ritornato qualcosa.