Skip to content

Commit 7fbf1bf

Browse files
committed
merging all conflicts
2 parents b64406d + 468e355 commit 7fbf1bf

File tree

7 files changed

+140
-23
lines changed

7 files changed

+140
-23
lines changed

1-js/02-first-steps/08-operators/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ alert( x ); // 5
223223

224224
Il fatto che il simbolo `=` sia un operatore e non un costrutto "magico" del linguaggio, ha delle interessanti implicazioni.
225225

226+
<<<<<<< HEAD
226227
Molti operatori in Javascript restituiscono un valore. Questo è ovvio per `+` e `-`, ma è altrettanto vero per `=`.
228+
=======
229+
All operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`.
230+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
227231
228232
La chiamata `x = value` scrive `value` in `x` *e quindi lo restituisce*.
229233

1-js/02-first-steps/18-javascript-specials/article.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,15 @@ Abbiamo studiato tre modi per creare funzioni in JavaScript:
275275
```
276276
277277
278+
<<<<<<< HEAD
278279
- Le funzioni possono avere variabili locali: queste vengono dichiarate all'interno del ciclo. Queste variabili sono visibili solamente all'interno della funzione.
279280
- I parametri possono avere valori di default: `function sum(a = 1, b = 2) {...}`.
280281
- Le funzioni ritornano sempre qualcosa. Se non c'è nessuna istruzione `return`, allora il risultato `undefined`.
282+
=======
283+
- Functions may have local variables: those declared inside its body or its parameter list. Such variables are only visible inside the function.
284+
- Parameters can have default values: `function sum(a = 1, b = 2) {...}`.
285+
- Functions always return something. If there's no `return` statement, then the result is `undefined`.
286+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
281287
282288
Per più informazioni: vedi <info:function-basics>, <info:arrow-functions-basics>.
283289

1-js/03-code-quality/01-debugging-chrome/article.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ Ci sono dei bottoni appositi nella parte superiore del pannello di destra. Provi
134134

135135
Continuando a cliccare eseguiremo lo script un passo per volta.
136136

137+
<<<<<<< HEAD
137138
<span class="devtools" style="background-position:-62px -192px"></span> -- "Step over": esegue il prossimo comando, ma *non entra nella funzione*, hotkey `key:F10`.
138139
: Molto simile al comando "Step", ma si comporta diversamente nel caso in cui la prossima istruzione sia una chiamata a funzione. Cioè: non una funzione built-in come `alert`, ma una funzione definita da noi.
140+
=======
141+
<span class="devtools" style="background-position:-62px -192px"></span> -- "Step over": run the next command, but *don't go into a function*, hotkey `key:F10`.
142+
: Similar to the previous "Step" command, but behaves differently if the next statement is a function call. That is: not a built-in, like `alert`, but a function of our own.
143+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
139144
140145
Il comando "Step" entra nella funzione e mette in pausa l'esecuzione, mentre "Step over" esegue la chiamata a funzione, saltandone il contenuto.
141146

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Le due strutture dati più utilizzate in JavaScritp sono `Object` e `Array`.
44

5+
<<<<<<< HEAD
56
Gli oggetti ci consentono di raccogliere molti pezzi di informazione in una singola entità, mentre gli array ci consentono di memorizzare collezioni ordinate. Possiamo quindi costruire un oggetto o un array e gestirlo come singola entità, oppure passarlo ad una funzione.
67

78
*L'assegnamento di destrutturazione* è una speciale sintassi che ci consente di "spacchettare" oggetti o array in un insieme di variabili, che in molti casi possono risultare più comode.
@@ -14,6 +15,24 @@ Un esempio di come un array viene destrutturato in variabili:
1415
```js
1516
// abbiamo un array con nome e cognome
1617
let arr = ["Ilya", "Kantor"]
18+
=======
19+
- Objects allow us to create a single entity that stores data items by key.
20+
- Arrays allow us to gather data items into an ordered list.
21+
22+
Although, when we pass those to a function, it may need not an object/array as a whole. It may need individual pieces.
23+
24+
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes that's more convenient.
25+
26+
Destructuring also works great with complex functions that have a lot of parameters, default values, and so on. Soon we'll see that.
27+
28+
## Array destructuring
29+
30+
Here's an example of how an array is destructured into variables:
31+
32+
```js
33+
// we have an array with the name and surname
34+
let arr = ["John", "Smith"]
35+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
1736

1837
*!*
1938
// assegnamento di destrutturazione
@@ -22,20 +41,29 @@ let arr = ["Ilya", "Kantor"]
2241
let [firstName, surname] = arr;
2342
*/!*
2443

25-
alert(firstName); // Ilya
26-
alert(surname); // Kantor
44+
alert(firstName); // John
45+
alert(surname); // Smith
2746
```
2847

2948
Ora possiamo lavorare con le variabili piuttosto che con i membri dell'array.
3049

3150
Risulta utile se combinata con `split` o altri metodi che ritorna un array:
3251

33-
```js
34-
let [firstName, surname] = "Ilya Kantor".split(' ');
52+
```js run
53+
let [firstName, surname] = "John Smith".split(' ');
54+
alert(firstName); // John
55+
alert(surname); // Smith
3556
```
3657

58+
<<<<<<< HEAD
3759
````smart header="\"Destrutturazione\" non significa \"distruzione\"."
3860
Viene chiamato "assegnamento di destrutturazione", perché "destrutturizza" copiando gli elementi all'interno di variabili. Ma l'array stesso non viene modificato.
61+
=======
62+
As you can see, the syntax is simple. There are several peculiar details though. Let's see more examples, to better understand it.
63+
64+
````smart header="\"Destructuring\" does not mean \"destructive\"."
65+
It's called "destructuring assignment," because it "destructurizes" by copying items into variables. But the array itself is not modified.
66+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
3967

4068
E' solo un modo breve per scrivere:
4169
```js
@@ -68,27 +96,38 @@ Nel codice sopra, il secondo elemento viene ignorato, il terzo viene assegnato a
6896
let [a, b, c] = "abc"; // ["a", "b", "c"]
6997
let [one, two, three] = new Set([1, 2, 3]);
7098
```
71-
99+
That works, because internally a destructuring assignment works by iterating over the right value. It's kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values.
72100
````
73101

74102

103+
<<<<<<< HEAD
75104
````smart header="Assegna a qualsiasi cosa ci sia dalla parte sinistra"
76105

77106
Possiamo inserire qualsiasi cosa sia "assegnabile" alla sinistra.
107+
=======
108+
````smart header="Assign to anything at the left-side"
109+
We can use any "assignables" at the left side.
110+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
78111

79112
Ad esempio, la proprietà di un oggetto:
80113
```js run
81114
let user = {};
82-
[user.name, user.surname] = "Ilya Kantor".split(' ');
115+
[user.name, user.surname] = "John Smith".split(' ');
83116

84-
alert(user.name); // Ilya
117+
alert(user.name); // John
118+
alert(user.surname); // Smith
85119
```
86120

87121
````
88122
123+
<<<<<<< HEAD
89124
````smart header="Cicla con .entries()"
90125
91126
Nel capitolo precedente abbiamo visto il metodo [Object.entries(obj)](mdn:js/Object/entries).
127+
=======
128+
````smart header="Looping with .entries()"
129+
In the previous chapter we saw the [Object.entries(obj)](mdn:js/Object/entries) method.
130+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
92131
93132
Possiamo utilizzarlo con la destrutturazione per eseguire cicli su chaivi/valore di un oggetto:
94133
@@ -106,62 +145,115 @@ for (let [key, value] of Object.entries(user)) {
106145
}
107146
```
108147
148+
<<<<<<< HEAD
109149
...Lo stesso vale per map:
150+
=======
151+
The similar code for a `Map` is simpler, as it's iterable:
152+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
110153
111154
```js run
112155
let user = new Map();
113156
user.set("name", "John");
114157
user.set("age", "30");
115158
116159
*!*
160+
// Map iterates as [key, value] pairs, very convenient for destructuring
117161
for (let [key, value] of user) {
118162
*/!*
119163
alert(`${key}:${value}`); // name:John, then age:30
120164
}
121165
```
122166
````
123167

168+
<<<<<<< HEAD
124169
```smart header="Il trucco dello scambio di varibili"
125170
Un metodo molto conosciuto per lo scambio dei valori di due variabili:
171+
=======
172+
````smart header="Swap variables trick"
173+
There's a well-known trick for swapping values of two variables using a destructuring assignment:
174+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
126175
127176
```js run
128177
let guest = "Jane";
129178
let admin = "Pete";
130179
180+
<<<<<<< HEAD
131181
// Scambio dei valori: rende guest=Pete, admin=Jane
182+
=======
183+
// Let's swap the values: make guest=Pete, admin=Jane
184+
*!*
185+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
132186
[guest, admin] = [admin, guest];
187+
*/!*
133188
134189
alert(`${guest} ${admin}`); // Pete Jane (scambiati con successo!)
135190
```
136191

137192
Qui creiamo un array temporaneo di due varibili e lo destrutturiamo immediatamente invertendo l'ordine delle variabili.
138193

194+
<<<<<<< HEAD
139195
In questo modo possiamo invertire l'ordine di più di due variabili.
140196

197+
=======
198+
We can swap more than two variables this way.
199+
````
200+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
141201
142202
### L'operatore resto '...'
143203
204+
<<<<<<< HEAD
144205
Se invece vogliamo destrutturare tutto, non solamente il primo elemento, ma raccogliere anche quello che segue -- passiamo un ulteriore parametro nella forma `"..."`:
206+
=======
207+
Usually, if the array is longer when the list at the left, the "extra" items are omitted.
208+
209+
For example, here only two items are taken, and the rest is just ignored:
210+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
145211
146212
```js run
147-
let [name1, name2, *!*...rest*/!*] = ["Julius", "Caesar", *!*"Consul", "of the Roman Republic"*/!*];
213+
let [name1, name2] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
148214
149215
alert(name1); // Julius
150216
alert(name2); // Caesar
217+
// Furher items aren't assigned anywhere
218+
```
219+
220+
If we'd like also to gather all that follows -- we can add one more parameter that gets "the rest" using three dots `"..."`:
221+
222+
```js run
223+
let [name1, name2, *!*...rest*/!*] = ["Julius", "Caesar", *!*"Consul", "of the Roman Republic"*/!*];
151224
152225
*!*
226+
<<<<<<< HEAD
153227
// Da notare che il tipo di `rest` è Array.
228+
=======
229+
// rest is array of items, starting from the 3rd one
230+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
154231
alert(rest[0]); // Consul
155232
alert(rest[1]); // of the Roman Republic
156233
alert(rest.length); // 2
157234
*/!*
158235
```
159236
237+
<<<<<<< HEAD
160238
La variabile `rest` è un array dei valori dell'array rimanenti. Possiamo utilizzare qualsiasi altro nome di variabile al posto di `rest`, è sufficiente accertarsi di inserire i tre punti prima del nome.
239+
=======
240+
The value of `rest` is the array of the remaining array elements.
241+
242+
We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignment.
243+
244+
```js run
245+
let [name1, name2, *!*...titles*/!*] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
246+
// now titles = ["Consul", "of the Roman Republic"]
247+
```
248+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
161249
162250
### Valori di default
163251
252+
<<<<<<< HEAD
164253
Se ci sono meno valori nell'array delle variabili da assegnare, non ci sarà alcun errore. I valori assenti vengono considerati undefined:
254+
=======
255+
If the array is shorter than the list of variables at the left, there'll be no errors. Absent values are considered undefined:
256+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
165257
166258
```js run
167259
*!*
@@ -186,7 +278,11 @@ alert(surname); // Anonymous (valore di default)
186278
187279
I valori di default possono essere anche espressioni complesse o anche delle chiamate a funzione. Verranno presi in considerazione solamente se non verrà fornito alcun valore.
188280
281+
<<<<<<< HEAD
189282
Ad esempio, qui usiamo la funzione `prompt` come default. La chiamata avverrà solamente nel secondo caso:
283+
=======
284+
For instance, here we use the `prompt` function for two defaults:
285+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
190286
191287
```js run
192288
// viene eseguito solo il prompt per il cognome
@@ -196,7 +292,7 @@ alert(name); // Julius (dall'array)
196292
alert(surname); // qualsiasi cosa provenga dal prompt
197293
```
198294
199-
295+
Please note: the `prompt` will run only for the missing value (`surname`).
200296
201297
## Destrutturazione di oggetti
202298
@@ -208,7 +304,11 @@ La sintassi è:
208304
let {var1, var2} = {var1:…, var2:…}
209305
```
210306
307+
<<<<<<< HEAD
211308
Abbiamo un oggetto alla destra dell'assegnazione, che vogliamo dividere in variabili. Nel lato sinistro abbiamo un "pattern" di proprietà corrispondenti. In questo semplice caso, abbiamo una lista di variabili raggruppate tra parentesi `{...}`.
309+
=======
310+
We should have an existing object at the right side, that we want to split into variables. The left side contains an object-like "pattern" for corresponding properties. In the simplest case, that's a list of variable names in `{...}`.
311+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
212312
213313
Ad esempio:
214314
@@ -228,7 +328,13 @@ alert(width); // 100
228328
alert(height); // 200
229329
```
230330
331+
<<<<<<< HEAD
231332
Le proprietà `options.title`, `options.width` e `options.height` vengono assegnate alle variabili corrispondenti. L'ordine non ha importanza. Questo codice funzionerebbe allo stesso modo:
333+
=======
334+
Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables.
335+
336+
The order does not matter. This works too:
337+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
232338
233339
```js
234340
// cambiato l'ordine delle proprietà in let {...}
@@ -237,7 +343,11 @@ let {height, width, title} = { title: "Menu", height: 200, width: 100 }
237343
238344
Il pattern alla sinistra potrebbe essere anche più complesso e specificare una mappatura tra proprietà e variabili.
239345
346+
<<<<<<< HEAD
240347
Se volessimo assegnare una proprietà ad una variabile con un altro nome, ad esempio, la proprietà `options.width` vogliamo inserirla in una variabile chiamata `w`, allora possiamo specificarlo con i due punti:
348+
=======
349+
If we want to assign a property to a variable with another name, for instance, make `options.width` go into the variable named `w`, then we can set the variable name using a colon:
350+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
241351
242352
```js run
243353
let options = {

1-js/06-advanced-functions/10-bind/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ The call to `mul.bind(null, 2)` creates a new function `double` that passes call
247247
248248
That's called [partial function application](https://en.wikipedia.org/wiki/Partial_application) -- we create a new function by fixing some parameters of the existing one.
249249
250-
Please note that here we actually don't use `this` here. But `bind` requires it, so we must put in something like `null`.
250+
Please note that we actually don't use `this` here. But `bind` requires it, so we must put in something like `null`.
251251
252252
The function `triple` in the code below triples the value:
253253

1-js/09-classes/02-class-inheritance/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Rabbit extends Animal {
150150
let rabbit = new Rabbit("White Rabbit");
151151
152152
rabbit.run(5); // White Rabbit runs with speed 5.
153-
rabbit.stop(); // White Rabbit stands still. White rabbit hides!
153+
rabbit.stop(); // White Rabbit stands still. White Rabbit hides!
154154
```
155155
156156
Ora `Rabbit` contiene il metodo `stop`, che richiama al suo interno il metodo `super.stop()`.

1-js/99-js-misc/03-currying-partials/article.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function curried(...args) {
155155
if (args.length >= func.length) { // (1)
156156
return func.apply(this, args);
157157
} else {
158-
return function pass(...args2) { // (2)
158+
return function(...args2) { // (2)
159159
return curried.apply(this, args.concat(args2));
160160
}
161161
}
@@ -164,18 +164,10 @@ function curried(...args) {
164164

165165
When we run it, there are two `if` execution branches:
166166

167-
1. Call now: if passed `args` count is the same as the original function has in its definition (`func.length`) or longer, then just pass the call to it.
168-
2. Get a partial: otherwise, `func` is not called yet. Instead, another wrapper `pass` is returned, that will re-apply `curried` providing previous arguments together with the new ones. Then on a new call, again, we'll get either a new partial (if not enough arguments) or, finally, the result.
167+
1. If passed `args` count is the same or more than the original function has in its definition (`func.length`) , then just pass the call to it using `func.apply`.
168+
2. Otherwise, get a partial: we don't call `func` just yet. Instead, another wrapper is returned, that will re-apply `curried` providing previous arguments together with the new ones.
169169

170-
For instance, let's see what happens in the case of `sum(a, b, c)`. Three arguments, so `sum.length = 3`.
171-
172-
For the call `curried(1)(2)(3)`:
173-
174-
1. The first call `curried(1)` remembers `1` in its Lexical Environment, and returns a wrapper `pass`.
175-
2. The wrapper `pass` is called with `(2)`: it takes previous args (`1`), concatenates them with what it got `(2)` and calls `curried(1, 2)` with them together. As the argument count is still less than 3, `curry` returns `pass`.
176-
3. The wrapper `pass` is called again with `(3)`, for the next call `pass(3)` takes previous args (`1`, `2`) and adds `3` to them, making the call `curried(1, 2, 3)` -- there are `3` arguments at last, they are given to the original function.
177-
178-
If that's still not obvious, just trace the calls sequence in your mind or on paper.
170+
Then, if we call it, again, we'll get either a new partial (if not enough arguments) or, finally, the result.
179171

180172
```smart header="Fixed-length functions only"
181173
The currying requires the function to have a fixed number of arguments.

0 commit comments

Comments
 (0)