Skip to content

Commit 82a94da

Browse files
committed
Resolve conflicts
1 parent 2d2f340 commit 82a94da

File tree

8 files changed

+65
-103
lines changed

8 files changed

+65
-103
lines changed

1-js/01-getting-started/2-manuals-specifications/article.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,17 @@ Uma nova versão dessa especificação é lançada todos os anos. Entre estes la
1313

1414
Para ler sobre as mais novas funcionalidades (*bleeding-edge features*), incluindo as que estão em fase de padronização (chamadas também de "estágio 3"), veja as suas propostas em <https://github.com/tc39/proposals>.
1515

16-
<<<<<<< HEAD
1716
E mais, se você está desenvolvendo para browsers, há outras especificações que cobrem esta demanda na [segunda parte](info:browser-environment) do tutorial.
18-
=======
19-
Also, if you're in developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial.
20-
>>>>>>> 3a0b3f4e31d4c4bbe90ed4c9c6e676a888ad8311
2117

2218
## Manuais
2319

24-
<<<<<<< HEAD
25-
- **MDN (Mozilla) JavaScript Reference** é um manual com exemplos e outras informações. É ótimo para um entendimento sobre funções, métodos da linguagem, etc.
26-
=======
27-
- **MDN (Mozilla) JavaScript Reference** is the main manual with examples and other information. It's great to get in-depth information about individual language functions, methods etc.
28-
>>>>>>> 3a0b3f4e31d4c4bbe90ed4c9c6e676a888ad8311
20+
- **MDN (Mozilla) JavaScript Reference** é um manual com exemplos e outras informações. É ótimo para um entendimento sobre funções da linguagem, métodos , etc.
2921

3022
Pode ser encontrado em <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
3123

32-
<<<<<<< HEAD
3324
Porém, às vezes é melhor fazer uma busca na internet. Apenas use "MDN [termo]" na busca, por exemplo: <https://google.com/search?q=MDN+parseInt> para procurar pela função `parseInt`.
3425

35-
- **MSDN** - Manual da Microsoft com muitas informações, incluindo JavaScript (frequentemente referido como JScript). Se precisar de algo específico para o Internet Explorer, é melhor ir por aqui: <http://msdn.microsoft.com/>.
36-
37-
Assim como para o manual da Mozilla, também podemos fazer uma busca na internet com frases do tipo "RegExp MSDN" ou "RegExp MSDN jscript".
38-
3926
## Tabelas de compatibilidade
40-
=======
41-
Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. <https://google.com/search?q=MDN+parseInt> to search for `parseInt` function.
42-
>>>>>>> 3a0b3f4e31d4c4bbe90ed4c9c6e676a888ad8311
4327

4428
JavaScript é uma linguagem em desenvolvimento, novas funcionalidades são adicionadas regularmente.
4529

1-js/03-code-quality/02-coding-style/article.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ Existem dois tipos de indentação:
115115
116116
Uma vantagem dos espaços sobre *tabs*, é que espaços permitem configurações de indentação mais flexíveis do que o símbolo "Tab".
117117
118-
<<<<<<< HEAD
119118
Por exemplo, podemos alinhar os argumentos com o parêntese de abertura, desta forma:
120-
=======
121-
For instance, we can align the parameters with the opening bracket, like this:
122-
>>>>>>> 3a0b3f4e31d4c4bbe90ed4c9c6e676a888ad8311
123119
124120
```js no-beautify
125121
show(parameters,

1-js/04-object-basics/03-garbage-collection/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ A general book "The Garbage Collection Handbook: The Art of Automatic Memory Man
207207

208208
If you are familiar with low-level programming, the more detailed information about V8 garbage collector is in the article [A tour of V8: Garbage Collection](http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection).
209209

210-
[V8 blog](http://v8project.blogspot.com/) also publishes articles about changes in memory management from time to time. Naturally, to learn the garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of V8 engineers. I'm saying: "V8", because it is best covered with articles in the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
210+
[V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn the garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of V8 engineers. I'm saying: "V8", because it is best covered with articles in the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
211211

212212
In-depth knowledge of engines is good when you need low-level optimizations. It would be wise to plan that as the next step after you're familiar with the language.
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11

22
describe("calculator", function() {
3-
let calculator;
4-
before(function() {
5-
sinon.stub(window, "prompt")
6-
7-
prompt.onCall(0).returns("2");
8-
prompt.onCall(1).returns("3");
9-
10-
calculator = new Calculator();
11-
calculator.read();
12-
});
3+
let calculator;
4+
before(function() {
5+
sinon.stub(window, "prompt")
136

14-
it("the read method asks for two values using prompt and remembers them in object properties", function() {
15-
assert.equal(calculator.a, 2);
16-
assert.equal(calculator.b, 3);
17-
});
18-
19-
it("when 2 and 3 are entered, the sum is 5", function() {
20-
assert.equal(calculator.sum(), 5);
21-
});
22-
23-
it("when 2 and 3 are entered, the product is 6", function() {
24-
assert.equal(calculator.mul(), 6);
25-
});
26-
27-
after(function() {
28-
prompt.restore();
7+
prompt.onCall(0).returns("2");
8+
prompt.onCall(1).returns("3");
9+
10+
calculator = new Calculator();
11+
calculator.read();
12+
});
13+
14+
it("the read method asks for two values using prompt and remembers them in object properties", function() {
15+
assert.equal(calculator.a, 2);
16+
assert.equal(calculator.b, 3);
17+
});
18+
19+
it("when 2 and 3 are entered, the sum is 5", function() {
20+
assert.equal(calculator.sum(), 5);
21+
});
22+
23+
it("when 2 and 3 are entered, the product is 6", function() {
24+
assert.equal(calculator.mul(), 6);
25+
});
26+
27+
after(function() {
28+
prompt.restore();
29+
});
2930
});
30-
});
31+

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let user = new function() {
8383
The constructor can't be called again, because it is not saved anywhere, just created and called. So this trick aims to encapsulate the code that constructs the single object, without future reuse.
8484
````
8585

86-
## Dual-syntax constructors: new.target
86+
## Constructor mode test: new.target
8787

8888
```smart header="Advanced stuff"
8989
The syntax from this section is rarely used, skip it unless you want to know everything.
@@ -109,7 +109,9 @@ new User(); // function User { ... }
109109
*/!*
110110
```
111111

112-
That can be used to allow both `new` and regular calls to work the same. That is, create the same object:
112+
That can be used inside the function to know whether it was called with `new`, "in constructor mode", or without it, "in regular mode".
113+
114+
We can also make both `new` and regular calls to do the same, like this:
113115

114116
```js run
115117
function User(name) {
@@ -210,6 +212,8 @@ john = {
210212
*/
211213
```
212214

215+
To create complex objects, there's a more advanced syntax, [classes](info:classes), that we'll cover later.
216+
213217
## Summary
214218

215219
- Constructor functions or, briefly, constructors, are regular functions, but there's a common agreement to name them with capital letter first.

1-js/04-object-basics/08-symbol/article.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A value of this type can be created using `Symbol()`:
1616
let id = Symbol();
1717
```
1818

19-
We can also give symbol a description (also called a symbol name), mostly useful for debugging purposes:
19+
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
2020

2121
```js
2222
// id is a symbol with the description "id"
@@ -94,7 +94,7 @@ What's the benefit of using `Symbol("id")` over a string `"id"`?
9494

9595
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed accidentally, the third-party code probably won't even see it, so it's probably all right to do.
9696

97-
Imagine that another script wants to have its own "id" property inside `user`, for its own purposes. That may be another JavaScript library, so the scripts are completely unaware of each other.
97+
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
9898

9999
Then that script can create its own `Symbol("id")`, like this:
100100

@@ -105,9 +105,9 @@ let id = Symbol("id");
105105
user[id] = "Their id value";
106106
```
107107

108-
There will be no conflict, because symbols are always different, even if they have the same name.
108+
There will be no conflict between our and their identifiers, because symbols are always different, even if they have the same name.
109109

110-
Now note that if we used a string `"id"` instead of a symbol for the same purpose, then there *would* be a conflict:
110+
...But if we used a string `"id"` instead of a symbol for the same purpose, then there *would* be a conflict:
111111

112112
```js
113113
let user = { name: "John" };
@@ -123,7 +123,7 @@ user.id = "Their id value"
123123

124124
### Symbols in an object literal
125125

126-
If we want to use a symbol in an object literal, we need square brackets.
126+
If we want to use a symbol in an object literal `{...}`, we need square brackets around it.
127127

128128
Like this:
129129

@@ -161,7 +161,7 @@ for (let key in user) alert(key); // name, age (no symbols)
161161
alert( "Direct: " + user[id] );
162162
```
163163

164-
That's a part of the general "hiding" concept. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
164+
`Object.keys(user)` also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
165165

166166
In contrast, [Object.assign](mdn:js/Object/assign) copies both string and symbol properties:
167167

@@ -180,13 +180,11 @@ There's no paradox here. That's by design. The idea is that when we clone an obj
180180

181181
## Global symbols
182182

183-
As we've seen, usually all symbols are different, even if they have the same names. But sometimes we want same-named symbols to be same entities.
184-
185-
For instance, different parts of our application want to access symbol `"id"` meaning exactly the same property.
183+
As we've seen, usually all symbols are different, even if they have the same name. But sometimes we want same-named symbols to be same entities. For instance, different parts of our application want to access symbol `"id"` meaning exactly the same property.
186184

187185
To achieve that, there exists a *global symbol registry*. We can create symbols in it and access them later, and it guarantees that repeated accesses by the same name return exactly the same symbol.
188186

189-
In order to create or read a symbol in the registry, use `Symbol.for(key)`.
187+
In order to read (create if absent) a symbol from the registry, use `Symbol.for(key)`.
190188

191189
That call checks the global registry, and if there's a symbol described as `key`, then returns it, otherwise creates a new symbol `Symbol(key)` and stores it in the registry by the given `key`.
192190

@@ -196,7 +194,7 @@ For instance:
196194
// read from the global registry
197195
let id = Symbol.for("id"); // if the symbol did not exist, it is created
198196

199-
// read it again
197+
// read it again (maybe from another part of the code)
200198
let idAgain = Symbol.for("id");
201199

202200
// the same symbol
@@ -218,22 +216,29 @@ For global symbols, not only `Symbol.for(key)` returns a symbol by name, but the
218216
For instance:
219217

220218
```js run
219+
// get symbol by name
221220
let sym = Symbol.for("name");
222221
let sym2 = Symbol.for("id");
223222

224-
// get name from symbol
223+
// get name by symbol
225224
alert( Symbol.keyFor(sym) ); // name
226225
alert( Symbol.keyFor(sym2) ); // id
227226
```
228227

229228
The `Symbol.keyFor` internally uses the global symbol registry to look up the key for the symbol. So it doesn't work for non-global symbols. If the symbol is not global, it won't be able to find it and returns `undefined`.
230229

230+
That said, any symbols have `description` property.
231+
231232
For instance:
232233

233234
```js run
234-
alert( Symbol.keyFor(Symbol.for("name")) ); // name, global symbol
235+
let globalSymbol = Symbol.for("name");
236+
let localSymbol = Symbol("name");
237+
238+
alert( Symbol.keyFor(globalSymbol) ); // name, global symbol
239+
alert( Symbol.keyFor(localSymbol) ); // undefined, not global
235240

236-
alert( Symbol.keyFor(Symbol("name2")) ); // undefined, the argument isn't a global symbol
241+
alert( localSymbol.description ); // name
237242
```
238243

239244
## System symbols
@@ -256,9 +261,9 @@ Other symbols will also become familiar when we study the corresponding language
256261

257262
`Symbol` is a primitive type for unique identifiers.
258263

259-
Symbols are created with `Symbol()` call with an optional description.
264+
Symbols are created with `Symbol()` call with an optional description (name).
260265

261-
Symbols are always different values, even if they have the same name. If we want same-named symbols to be equal, then we should use the global registry: `Symbol.for(key)` returns (creates if needed) a global symbol with `key` as the name. Multiple calls of `Symbol.for` return exactly the same symbol.
266+
Symbols are always different values, even if they have the same name. If we want same-named symbols to be equal, then we should use the global registry: `Symbol.for(key)` returns (creates if needed) a global symbol with `key` as the name. Multiple calls of `Symbol.for` with the same `key` return exactly the same symbol.
262267

263268
Symbols have two main use cases:
264269

@@ -269,4 +274,4 @@ Symbols have two main use cases:
269274

270275
2. There are many system symbols used by JavaScript which are accessible as `Symbol.*`. We can use them to alter some built-in behaviors. For instance, later in the tutorial we'll use `Symbol.iterator` for [iterables](info:iterable), `Symbol.toPrimitive` to setup [object-to-primitive conversion](info:object-toprimitive) and so on.
271276

272-
Technically, symbols are not 100% hidden. There is a built-in method [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) that allows us to get all symbols. Also there is a method named [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys of an object including symbolic ones. So they are not really hidden. But most libraries, built-in methods and syntax constructs adhere to a common agreement that they are. And the one who explicitly calls the aforementioned methods probably understands well what he's doing.
277+
Technically, symbols are not 100% hidden. There is a built-in method [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) that allows us to get all symbols. Also there is a method named [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys of an object including symbolic ones. So they are not really hidden. But most libraries, built-in functions and syntax constructs don't use these methods.

1-js/11-async/08-async-await/article.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function f() {
1212
}
1313
```
1414

15-
The word "async" before a function means one simple thing: a function always returns a promise. Even If a function actually returns a non-promise value, prepending the function definition with the "async" keyword directs JavaScript to automatically wrap that value in a resolved promise.
15+
The word "async" before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.
1616

1717
For instance, this function returns a resolved promise with the result of `1`; let's test it:
1818

@@ -172,7 +172,7 @@ f();
172172
If `await` gets a non-promise object with `.then`, it calls that method providing the built-in functions `resolve` and `reject` as arguments (just as it does for a regular `Promise` executor). Then `await` waits until one of them is called (in the example above it happens in the line `(*)`) and then proceeds with the result.
173173
````
174174
175-
````smart header="Async methods"
175+
````smart header="Async class methods"
176176
To declare an async class method, just prepend it with `async`:
177177
178178
```js run
@@ -215,7 +215,7 @@ async function f() {
215215
}
216216
```
217217

218-
In real situations, the promise may take some time before it rejects. So `await` will wait, and then throw an error.
218+
In real situations, the promise may take some time before it rejects. In that case there will be a delay before `await` throws an error.
219219

220220
We can catch that error using `try..catch`, the same way as a regular `throw`:
221221

@@ -289,34 +289,6 @@ In the case of an error, it propagates as usual, from the failed promise to `Pro
289289

290290
````
291291
292-
## Microtask queue [#microtask-queue]
293-
294-
As we've seen in the chapter <info:microtask-queue>, promise handlers are executed asynchronously. Every `.then/catch/finally` handler first gets into the "microtask queue" and executed after the current code is complete.
295-
296-
`Async/await` is based on promises, so it uses the same microtask queue internally, and has the similar priority over macrotasks.
297-
298-
For instance, we have:
299-
- `setTimeout(handler, 0)`, that should run `handler` with zero delay.
300-
- `let x = await f()`, function `f()` is async, but returns immediately.
301-
302-
Which one runs first if `await` is *below* `setTimeout` in the code?
303-
304-
```js run
305-
async function f() {
306-
return 1;
307-
}
308-
309-
(async () => {
310-
setTimeout(() => alert('timeout'), 0);
311-
312-
await f();
313-
314-
alert('await');
315-
})();
316-
```
317-
318-
There's no ambiguity here: `await` always finishes first, because (as a microtask) it has a higher priority than `setTimeout` handling.
319-
320292
## Summary
321293
322294
The `async` keyword before a function has two effects:

2-ui/4-forms-controls/1-form-elements/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Forms and control elements, such as `<input>` have a lot of special properties and events.
44

5-
Working with forms can be much more convenient if we know them.
5+
Working with forms will be much more convenient when we learn them.
66

77
## Navigation: form and elements
88

99
Document forms are members of the special collection `document.forms`.
1010

11-
That's a *named* collection: we can use both the name and the number to get the form.
11+
That's a so-called "named collection": it's both named and ordered. We can use both the name or the number in the document to get the form.
1212

1313
```js no-beautify
1414
document.forms.my - the form with name="my"
@@ -155,7 +155,7 @@ Let's talk about form controls.
155155
156156
### input and textarea
157157
158-
Normally, we can access the value as `input.value` or `input.checked` for checkboxes.
158+
We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes.
159159
160160
Like this:
161161
@@ -227,7 +227,7 @@ Here's an example of how to get selected values from a multi-select:
227227
</script>
228228
```
229229
230-
The full specification of the `<select>` element is available at <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
230+
The full specification of the `<select>` element is available in the specification <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
231231
232232
### new Option
233233
@@ -241,7 +241,7 @@ This syntax is optional. We can use `document.createElement('option')` and set a
241241
242242
- `text` -- the text inside the option,
243243
- `value` -- the option value,
244-
- `defaultSelected` -- if `true`, then `selected` attribute is created,
244+
- `defaultSelected` -- if `true`, then `selected` HTML-attribute is created,
245245
- `selected` -- if `true`, then the option is selected.
246246
247247
The difference between `defaultSelected` and `selected` is that `defaultSelected` sets the HTML-attribute (that we can get using `option.getAttribute('selected')`, while `selected` sets whether the option is selected or not.

0 commit comments

Comments
 (0)