Skip to content

Commit 5d572f8

Browse files
committed
merging all conflicts
2 parents f496f9c + 468e355 commit 5d572f8

File tree

11 files changed

+179
-130
lines changed

11 files changed

+179
-130
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,21 @@ Ferramentas modernas tornam a transpilação muito rápida e transparente, permi
106106

107107
Exemplos de tais linguagens:
108108

109+
<<<<<<< HEAD
109110
- [CoffeeScript](http://coffeescript.org/) é um "açúcar sintático" para JavaScript. Ele introduz uma sintaxe mais curta, permitindo-nos escrever um código mais claro e preciso. Normalmente, Ruby devs gostam dele.
110111
- [TypeScript](http://www.typescriptlang.org/) está concentrado em adicionar "estritos tipos de dados" para simplificar o desenvolvimento e suporte de sistemas complexos. É desenvolvido pela Microsoft.
111112
- [Flow](http://flow.org/) também adiciona tipos de dados, mas de uma forma diferente. Desenvolvido pela Facebook.
112113
- [Dart](https://www.dartlang.org/) é uma linguagem autônoma que tem seu próprio interpretador que roda em ambientes fora do navegador (como aplicativos móveis), mas também pode ser transpilada para JavaScript. Desenvolvida pela Google.
113114
- [Brython](https://brython.info/) é um transpilador de Python para JavaScript que permite escrever aplicativos em puro Python, sem JavaScript.
114115
- [Kotlin](https://kotlinlang.org/docs/js-overview.html) é uma linguagem de programação moderna, concisa e segura, que pode ser usada no navegador ou no Node.
116+
=======
117+
- [CoffeeScript](http://coffeescript.org/) is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
118+
- [TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
119+
- [Flow](http://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
120+
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
121+
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
122+
- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node.
123+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
115124
116125
Há mais. Claro que, mesmo que usemos uma dessas linguagens transpiladas, também devemos saber JavaScript para entender o que estamos fazendo.
117126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ alert( x ); // 5
219219
220220
The fact of `=` being an operator, not a "magical" language construct has an interesting implication.
221221
222-
Most operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`.
222+
All operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`.
223223

224224
The call `x = value` writes the `value` into `x` *and then returns it*.
225225

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ We covered three ways to create a function in JavaScript:
273273
```
274274
275275
276-
- Functions may have local variables: those declared inside its body. Such variables are only visible inside the function.
276+
- Functions may have local variables: those declared inside its body or its parameter list. Such variables are only visible inside the function.
277277
- Parameters can have default values: `function sum(a = 1, b = 2) {...}`.
278278
- Functions always return something. If there's no `return` statement, then the result is `undefined`.
279279

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 @@ Existem botões para isso no topo do painel direito. Vamos interagir com eles.
134134

135135
Continuando a clicar nele, passará por todas as instruções do programa, uma por uma.
136136

137+
<<<<<<< HEAD
137138
<span class="devtools" style="background-position:-62px -192px"></span> -- "Step over": execute o próximo comando, mas *mas não vá para dentro de uma função*, atalho `key:F10`.
138139
: Similar ao comando "Step" anterior, mas com um comportamento diferente se a próxima instrução for uma chamada de função. Isto é: não uma incorporada (*built-in*), como `alert`, mas uma função sua.
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
O comando "Step", vai para dentro dela e suspende a execução na sua primeira linha, ao contrário de "Step over" que executa essa chamada de função aninhada invisívelmente, saltando sobre o funcionamento interno da função.
141146

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

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,50 @@
22

33
The two most used data structures in JavaScript are `Object` and `Array`.
44

5+
<<<<<<< HEAD
56
Objects allow us to pack many pieces of information into a single entity and arrays allow us to store ordered collections. So we can make an object or an array and handle it as a single entity, or maybe pass it to a function call.
67

78
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes they are more convenient. Destructuring also works great with complex functions that have a lot of parameters, default values, and soon we'll see how these are handled too.
9+
=======
10+
- Objects allow us to create a single entity that stores data items by key.
11+
- Arrays allow us to gather data items into an ordered list.
12+
13+
Although, when we pass those to a function, it may need not an object/array as a whole. It may need individual pieces.
14+
15+
*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.
16+
17+
Destructuring also works great with complex functions that have a lot of parameters, default values, and so on. Soon we'll see that.
18+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
819
920
## Array destructuring
1021

11-
An example of how the array is destructured into variables:
22+
Here's an example of how an array is destructured into variables:
1223

1324
```js
1425
// we have an array with the name and surname
15-
let arr = ["Ilya", "Kantor"]
26+
let arr = ["John", "Smith"]
1627

1728
*!*
1829
// destructuring assignment
1930
let [firstName, surname] = arr;
2031
*/!*
2132

22-
alert(firstName); // Ilya
23-
alert(surname); // Kantor
33+
alert(firstName); // John
34+
alert(surname); // Smith
2435
```
2536

2637
Now we can work with variables instead of array members.
2738

2839
It looks great when combined with `split` or other array-returning methods:
2940

30-
```js
31-
let [firstName, surname] = "Ilya Kantor".split(' ');
41+
```js run
42+
let [firstName, surname] = "John Smith".split(' ');
43+
alert(firstName); // John
44+
alert(surname); // Smith
3245
```
3346

47+
As you can see, the syntax is simple. There are several peculiar details though. Let's see more examples, to better understand it.
48+
3449
````smart header="\"Destructuring\" does not mean \"destructive\"."
3550
It's called "destructuring assignment," because it "destructurizes" by copying items into variables. But the array itself is not modified.
3651
@@ -65,26 +80,25 @@ In the code above, the second element of the array is skipped, the third one is
6580
let [a, b, c] = "abc"; // ["a", "b", "c"]
6681
let [one, two, three] = new Set([1, 2, 3]);
6782
```
68-
83+
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.
6984
````
7085

7186

7287
````smart header="Assign to anything at the left-side"
73-
7488
We can use any "assignables" at the left side.
7589
7690
For instance, an object property:
7791
```js run
7892
let user = {};
79-
[user.name, user.surname] = "Ilya Kantor".split(' ');
93+
[user.name, user.surname] = "John Smith".split(' ');
8094
81-
alert(user.name); // Ilya
95+
alert(user.name); // John
96+
alert(user.surname); // Smith
8297
```
8398
8499
````
85100

86101
````smart header="Looping with .entries()"
87-
88102
In the previous chapter we saw the [Object.entries(obj)](mdn:js/Object/entries) method.
89103
90104
We can use it with destructuring to loop over keys-and-values of an object:
@@ -103,62 +117,85 @@ for (let [key, value] of Object.entries(user)) {
103117
}
104118
```
105119
106-
...And the same for a map:
120+
The similar code for a `Map` is simpler, as it's iterable:
107121
108122
```js run
109123
let user = new Map();
110124
user.set("name", "John");
111125
user.set("age", "30");
112126
113127
*!*
128+
<<<<<<< HEAD
114129
for (let [key, value] of user.entries()) {
130+
=======
131+
// Map iterates as [key, value] pairs, very convenient for destructuring
132+
for (let [key, value] of user) {
133+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
115134
*/!*
116135
alert(`${key}:${value}`); // name:John, then age:30
117136
}
118137
```
119138
````
120139

121-
```smart header="Swap variables trick"
122-
A well-known trick for swapping values of two variables:
140+
````smart header="Swap variables trick"
141+
There's a well-known trick for swapping values of two variables using a destructuring assignment:
123142
124143
```js run
125144
let guest = "Jane";
126145
let admin = "Pete";
127146
128-
// Swap values: make guest=Pete, admin=Jane
147+
// Let's swap the values: make guest=Pete, admin=Jane
148+
*!*
129149
[guest, admin] = [admin, guest];
150+
*/!*
130151
131152
alert(`${guest} ${admin}`); // Pete Jane (successfully swapped!)
132153
```
133154
134155
Here we create a temporary array of two variables and immediately destructure it in swapped order.
135156
136157
We can swap more than two variables this way.
137-
158+
````
138159

139160
### The rest '...'
140161

141-
If we want not just to get first values, but also to gather all that follows -- we can add one more parameter that gets "the rest" using three dots `"..."`:
162+
Usually, if the array is longer when the list at the left, the "extra" items are omitted.
163+
164+
For example, here only two items are taken, and the rest is just ignored:
142165

143166
```js run
144-
let [name1, name2, *!*...rest*/!*] = ["Julius", "Caesar", *!*"Consul", "of the Roman Republic"*/!*];
167+
let [name1, name2] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
145168

146169
alert(name1); // Julius
147170
alert(name2); // Caesar
171+
// Furher items aren't assigned anywhere
172+
```
173+
174+
If we'd like also to gather all that follows -- we can add one more parameter that gets "the rest" using three dots `"..."`:
175+
176+
```js run
177+
let [name1, name2, *!*...rest*/!*] = ["Julius", "Caesar", *!*"Consul", "of the Roman Republic"*/!*];
148178
149179
*!*
150-
// Note that type of `rest` is Array.
180+
// rest is array of items, starting from the 3rd one
151181
alert(rest[0]); // Consul
152182
alert(rest[1]); // of the Roman Republic
153183
alert(rest.length); // 2
154184
*/!*
155185
```
156186

157-
The value of `rest` is the array of the remaining array elements. 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.
187+
The value of `rest` is the array of the remaining array elements.
188+
189+
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.
190+
191+
```js run
192+
let [name1, name2, *!*...titles*/!*] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
193+
// now titles = ["Consul", "of the Roman Republic"]
194+
```
158195

159196
### Default values
160197

161-
If there are fewer values in the array than variables in the assignment, there will be no error. Absent values are considered undefined:
198+
If the array is shorter than the list of variables at the left, there'll be no errors. Absent values are considered undefined:
162199

163200
```js run
164201
*!*
@@ -183,7 +220,7 @@ alert(surname); // Anonymous (default used)
183220

184221
Default values can be more complex expressions or even function calls. They are evaluated only if the value is not provided.
185222

186-
For instance, here we use the `prompt` function for two defaults. But it will run only for the missing one:
223+
For instance, here we use the `prompt` function for two defaults:
187224

188225
```js run
189226
// runs only prompt for surname
@@ -193,7 +230,7 @@ alert(name); // Julius (from array)
193230
alert(surname); // whatever prompt gets
194231
```
195232

196-
233+
Please note: the `prompt` will run only for the missing value (`surname`).
197234

198235
## Object destructuring
199236

@@ -205,7 +242,7 @@ The basic syntax is:
205242
let {var1, var2} = {var1:…, var2:…}
206243
```
207244

208-
We have an existing object at the right side, that we want to split into variables. The left side contains a "pattern" for corresponding properties. In the simple case, that's a list of variable names in `{...}`.
245+
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 `{...}`.
209246

210247
For instance:
211248

@@ -225,7 +262,9 @@ alert(width); // 100
225262
alert(height); // 200
226263
```
227264

228-
Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables. The order does not matter. This works too:
265+
Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables.
266+
267+
The order does not matter. This works too:
229268

230269
```js
231270
// changed the order of properties in let {...}
@@ -234,7 +273,7 @@ let {height, width, title} = { title: "Menu", height: 200, width: 100 }
234273

235274
The pattern on the left side may be more complex and specify the mapping between properties and variables.
236275

237-
If we want to assign a property to a variable with another name, for instance, `options.width` to go into the variable named `w`, then we can set it using a colon:
276+
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:
238277

239278
```js run
240279
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ class Rabbit extends Animal {
151151
let rabbit = new Rabbit("White Rabbit");
152152
153153
rabbit.run(5); // White Rabbit runs with speed 5.
154+
<<<<<<< HEAD
154155
rabbit.stop(); // White Rabbit stopped. White rabbit hides!
156+
=======
157+
rabbit.stop(); // White Rabbit stands still. White Rabbit hides!
158+
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
155159
```
156160
157161
Now `Rabbit` has the `stop` method that calls the parent `super.stop()` in the process.

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)