Skip to content

Commit 24bc756

Browse files
committed
Resolve conflicts.
1 parent 5d572f8 commit 24bc756

File tree

5 files changed

+75
-87
lines changed

5 files changed

+75
-87
lines changed

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

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

107107
Exemplos de tais linguagens:
108108

109-
<<<<<<< HEAD
110109
- [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.
111110
- [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.
112111
- [Flow](http://flow.org/) também adiciona tipos de dados, mas de uma forma diferente. Desenvolvido pela Facebook.
113112
- [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.
114113
- [Brython](https://brython.info/) é um transpilador de Python para JavaScript que permite escrever aplicativos em puro Python, sem JavaScript.
115114
- [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
124115

125116
Há mais. Claro que, mesmo que usemos uma dessas linguagens transpiladas, também devemos saber JavaScript para entender o que estamos fazendo.
126117

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,8 @@ 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
138137
<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`.
139-
: 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
138+
: 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 nossa.
144139

145140
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.
146141

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

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

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

5-
<<<<<<< HEAD
6-
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.
7-
8-
*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-
=======
105
- Objects allow us to create a single entity that stores data items by key.
116
- Arrays allow us to gather data items into an ordered list.
127

@@ -15,7 +10,6 @@ Although, when we pass those to a function, it may need not an object/array as a
1510
*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.
1611

1712
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
1913

2014
## Array destructuring
2115

@@ -27,6 +21,8 @@ let arr = ["John", "Smith"]
2721

2822
*!*
2923
// destructuring assignment
24+
// sets firstName = arr[0]
25+
// and surname = arr[1]
3026
let [firstName, surname] = arr;
3127
*/!*
3228

@@ -69,7 +65,7 @@ let [firstName, , title] = ["Julius", "Caesar", "Consul", "of the Roman Republic
6965
alert( title ); // Consul
7066
```
7167
72-
In the code above, the second element of the array is skipped, the third one is assigned to `title`, and the rest of the array is also skipped.
68+
In the code above, the second element of the array is skipped, the third one is assigned to `title`, and the rest of the array items is also skipped (as there are no variables for them).
7369
````
7470

7571
````smart header="Works with any iterable on the right-side"
@@ -125,12 +121,8 @@ user.set("name", "John");
125121
user.set("age", "30");
126122
127123
*!*
128-
<<<<<<< HEAD
129-
for (let [key, value] of user.entries()) {
130-
=======
131124
// Map iterates as [key, value] pairs, very convenient for destructuring
132125
for (let [key, value] of user) {
133-
>>>>>>> 468e3552884851fcef331fbdfd58096652964b5f
134126
*/!*
135127
alert(`${key}:${value}`); // name:John, then age:30
136128
}
@@ -267,7 +259,7 @@ Properties `options.title`, `options.width` and `options.height` are assigned to
267259
The order does not matter. This works too:
268260

269261
```js
270-
// changed the order of properties in let {...}
262+
// changed the order in let {...}
271263
let {height, width, title} = { title: "Menu", height: 200, width: 100 }
272264
```
273265

@@ -316,7 +308,7 @@ alert(height); // 200
316308

317309
Just like with arrays or function parameters, default values can be any expressions or even function calls. They will be evaluated if the value is not provided.
318310

319-
The code below asks for width, but not the title.
311+
In the code below `prompt` asks for `width`, but not for `title`:
320312

321313
```js run
322314
let options = {
@@ -328,7 +320,7 @@ let {width = prompt("width?"), title = prompt("title?")} = options;
328320
*/!*
329321

330322
alert(title); // Menu
331-
alert(width); // (whatever you the result of prompt is)
323+
alert(width); // (whatever the result of prompt is)
332324
```
333325

334326
We also can combine both the colon and equality:
@@ -347,11 +339,26 @@ alert(w); // 100
347339
alert(h); // 200
348340
```
349341

350-
### The rest operator
342+
If we have a complex object with many properties, we can extract only what we need:
343+
344+
```js run
345+
let options = {
346+
title: "Menu",
347+
width: 100,
348+
height: 200
349+
};
350+
351+
// only extract title as a variable
352+
let { title } = options;
353+
354+
alert(title); // Menu
355+
```
356+
357+
### The rest pattern "..."
351358

352359
What if the object has more properties than we have variables? Can we take some and then assign the "rest" somewhere?
353360

354-
The specification for using the rest operator (three dots) here is almost in the standard, but most browsers do not support it yet.
361+
We can use the rest pattern, just like we did with arrays. It's not supported by some older browsers (IE, use Babel to polyfill it), but works in modern ones.
355362

356363
It looks like this:
357364

@@ -363,6 +370,8 @@ let options = {
363370
};
364371

365372
*!*
373+
// title = property named title
374+
// rest = object with the rest of properties
366375
let {title, ...rest} = options;
367376
*/!*
368377

@@ -371,10 +380,8 @@ alert(rest.height); // 200
371380
alert(rest.width); // 100
372381
```
373382

374-
375-
376-
````smart header="Gotcha without `let`"
377-
In the examples above variables were declared right before the assignment: `let {…} = {…}`. Of course, we could use existing variables too. But there's a catch.
383+
````smart header="Gotcha if there's no `let`"
384+
In the examples above variables were declared right in the assignment: `let {…} = {…}`. Of course, we could use existing variables too, without `let`. But there's a catch.
378385

379386
This won't work:
380387
```js run
@@ -407,14 +414,13 @@ let title, width, height;
407414

408415
alert( title ); // Menu
409416
```
410-
411417
````
412418
413419
## Nested destructuring
414420
415-
If an object or an array contain other objects and arrays, we can use more complex left-side patterns to extract deeper portions.
421+
If an object or an array contain other nested objects and arrays, we can use more complex left-side patterns to extract deeper portions.
416422
417-
In the code below `options` has another object in the property `size` and an array in the property `items`. The pattern at the left side of the assignment has the same structure:
423+
In the code below `options` has another object in the property `size` and an array in the property `items`. The pattern at the left side of the assignment has the same structure to extract values from them:
418424
419425
```js run
420426
let options = {
@@ -423,10 +429,10 @@ let options = {
423429
height: 200
424430
},
425431
items: ["Cake", "Donut"],
426-
extra: true // something extra that we will not destruct
432+
extra: true
427433
};
428434

429-
// destructuring assignment on multiple lines for clarity
435+
// destructuring assignment split in multiple lines for clarity
430436
let {
431437
size: { // put size here
432438
width,
@@ -449,17 +455,11 @@ All properties of `options` object except `extra` that is absent in the left par
449455
450456
Finally, we have `width`, `height`, `item1`, `item2` and `title` from the default value.
451457
452-
That often happens with destructuring assignments. We have a complex object with many properties and want to extract only what we need.
453-
454-
Even here it happens:
455-
```js
456-
// take size as a whole into a variable, ignore the rest
457-
let { size } = options;
458-
```
458+
Note that there are no variables for `size` and `items`, as we take their content instead.
459459
460460
## Smart function parameters
461461
462-
There are times when a function may have many parameters, most of which are optional. That's especially true for user interfaces. Imagine a function that creates a menu. It may have a width, a height, a title, items list and so on.
462+
There are times when a function has many parameters, most of which are optional. That's especially true for user interfaces. Imagine a function that creates a menu. It may have a width, a height, a title, items list and so on.
463463
464464
Here's a bad way to write such function:
465465
@@ -526,29 +526,28 @@ function showMenu({
526526
showMenu(options);
527527
```
528528
529-
The syntax is the same as for a destructuring assignment:
529+
The full syntax is the same as for a destructuring assignment:
530530
```js
531531
function({
532-
incomingProperty: parameterName = defaultValue
532+
incomingProperty: varName = defaultValue
533533
...
534534
})
535535
```
536536

537+
Then, for an object of parameters, there will be a variable `varName` for property `incomingProperty`, with `defaultValue` by default.
538+
537539
Please note that such destructuring assumes that `showMenu()` does have an argument. If we want all values by default, then we should specify an empty object:
538540

539541
```js
540-
showMenu({});
541-
542+
showMenu({}); // ok, all values are default
542543

543544
showMenu(); // this would give an error
544545
```
545546

546-
We can fix this by making `{}` the default value for the whole destructuring thing:
547-
547+
We can fix this by making `{}` the default value for the whole object of parameters:
548548

549549
```js run
550-
// simplified parameters a bit for clarity
551-
function showMenu(*!*{ title = "Menu", width = 100, height = 200 } = {}*/!*) {
550+
function showMenu({ title = "Menu", width = 100, height = 200 }*!* = {}*/!*) {
552551
alert( `${title} ${width} ${height}` );
553552
}
554553

@@ -560,19 +559,21 @@ In the code above, the whole arguments object is `{}` by default, so there's alw
560559
## Summary
561560

562561
- Destructuring assignment allows for instantly mapping an object or array onto many variables.
563-
- The object syntax:
562+
- The full object syntax:
564563
```js
565-
let {prop : varName = default, ...} = object
564+
let {prop : varName = default, ...rest} = object
566565
```
567566

568567
This means that property `prop` should go into the variable `varName` and, if no such property exists, then the `default` value should be used.
569568

570-
- The array syntax:
569+
Object properties that have no mapping are copied to the `rest` object.
570+
571+
- The full array syntax:
571572

572573
```js
573574
let [item1 = default, item2, ...rest] = array
574575
```
575576

576577
The first item goes to `item1`; the second goes into `item2`, all the rest makes the array `rest`.
577578

578-
- For more complex cases, the left side must have the same structure as the right one.
579+
- It's possible to extract data from nested arrays/objects, for that the left side must have the same structure as the right one.

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ libs:
55

66
# Function binding
77

8-
When using `setTimeout` with object methods or passing object methods along, there's a known problem: "losing `this`".
8+
When passing object methods as callbacks, for instance to `setTimeout`, there's a known problem: "losing `this`".
99

10-
Suddenly, `this` just stops working right. The situation is typical for novice developers, but happens with experienced ones as well.
10+
In this chapter we'll see the ways to fix it.
1111

1212
## Losing "this"
1313

14-
We already know that in JavaScript it's easy to lose `this`. Once a method is passed somewhere separately from the object -- `this` is lost.
14+
We've already seen examples of losing `this`. Once a method is passed somewhere separately from the object -- `this` is lost.
1515

1616
Here's how it may happen with `setTimeout`:
1717

@@ -37,7 +37,7 @@ let f = user.sayHi;
3737
setTimeout(f, 1000); // lost user context
3838
```
3939

40-
The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.js, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases as we'll see, usually `this` just becomes `undefined`.
40+
The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.js, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases, usually `this` just becomes `undefined`.
4141

4242
The task is quite typical -- we want to pass an object method somewhere else (here -- to the scheduler) where it will be called. How to make sure that it will be called in the right context?
4343

@@ -102,7 +102,7 @@ The basic syntax is:
102102
```js
103103
// more complex syntax will come a little later
104104
let boundFunc = func.bind(context);
105-
````
105+
```
106106

107107
The result of `func.bind(context)` is a special function-like "exotic object", that is callable as function and transparently passes the call to `func` setting `this=context`.
108108

@@ -321,4 +321,8 @@ Also there's a ready [_.partial](https://lodash.com/docs#partial) implementation
321321
322322
Method `func.bind(context, ...args)` returns a "bound variant" of function `func` that fixes the context `this` and first arguments if given.
323323
324-
Usually we apply `bind` to fix `this` in an object method, so that we can pass it somewhere. For example, to `setTimeout`. There are more reasons to `bind` in the modern development, we'll meet them later.
324+
Usually we apply `bind` to fix `this` for an object method, so that we can pass it somewhere. For example, to `setTimeout`.
325+
326+
When we fix some arguments of an existing function, the resulting (less universal) function is called *partially applied* or *partial*.
327+
328+
Partials are convenient when we don't want to repeat the same argument over and over again. Like if we have a `send(from, to)` function, and `from` should always be the same for our task, we can get a partial and go on with it.

0 commit comments

Comments
 (0)