Skip to content

Commit 5b8a4bc

Browse files
authored
Merge pull request #196 from javascript-tutorial/sync-23da191b
Sync with upstream @ 23da191
2 parents 75b3067 + 095a7c3 commit 5b8a4bc

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

1-js/02-first-steps/01-hello-world/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Então, primeiro, vamos ver como anexar um script a uma página. Para ambientes
99

1010
## A tag "script"
1111

12-
Os programas JavaScript podem ser inseridos em qualquer parte de um documento HTML com a ajuda da tag `<script>`.
12+
Os programas JavaScript podem ser inseridos em quase qualquer parte de um documento HTML com a ajuda da tag `<script>`.
1313

1414
Por exemplo:
1515

1-js/04-object-basics/01-object/article.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,6 @@ let user = {
9292
```
9393
Esta é chamada de vírgula à direita (*trailing comma*) ou "vírgula pendurada" (*hanging comma*). Ela facilita o adicionar/remover/mover propriedades, porque todas as linhas se tornam semelhantes.
9494

95-
````smart header="Objeto com const pode ser alterado"
96-
Por favor, note: um objeto declarado como `const` *pode* ser modificado.
97-
98-
Por exemplo:
99-
100-
```js run
101-
const user = {
102-
name: "John"
103-
};
104-
105-
*!*
106-
user.name = "Pete"; // (*)
107-
*/!*
108-
109-
alert(user.name); // Pete
110-
```
111-
112-
Poderá parecer que a linha `(*)` irá causar um erro, mas não. A `const` fixa o valor de `user`, mas não o seu conteúdo.
113-
114-
A `const` dará um erro apenas se tentarmos mudar `user=...` como um todo.
115-
116-
Há outra forma para tornar constantes as propriedades de um objeto, que iremos ver mais adiante no capítulo <info:property-descriptors>.
117-
````
118-
11995
## Parênteses retos
12096

12197
Para propriedades com múltiplas palavras, o acesso por ponto não funciona:

1-js/04-object-basics/02-object-copy/article.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ admin.name = 'Pete'; // changed by the "admin" reference
7373
alert(*!*user.name*/!*); // 'Pete', changes are seen from the "user" reference
7474
```
7575
76-
7776
It's just as if we had a cabinet with two keys and used one of them (`admin`) to get into it. Then, if we later use another key (`user`) we can see changes.
7877
7978
## Comparison by reference
@@ -230,6 +229,30 @@ To fix that, we should use the cloning loop that examines each value of `user[ke
230229
231230
We can use recursion to implement it. Or, not to reinvent the wheel, take an existing implementation, for instance [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep) from the JavaScript library [lodash](https://lodash.com).
232231
232+
```smart header="Const objects can be modified"
233+
An important "side effect" of storing objects as references is that an object declared as `const` *can* be modified.
234+
235+
For instance:
236+
237+
```js run
238+
const user = {
239+
name: "John"
240+
};
241+
242+
*!*
243+
user.name = "Pete"; // (*)
244+
*/!*
245+
246+
alert(user.name); // Pete
247+
```
248+
249+
It might seem that the line `(*)` would cause an error, but no. The value of `user` is constant, it must always reference the same object. But properties of that object are free to change.
250+
251+
In other words, the `const user` gives an error only if we try to set `user=...` as a whole, and that's all.
252+
253+
That said, if we really need to make constant object properties, it's also possible, but using totally different methods, we'll mention that in the chapter <info:property-descriptors>.
254+
```
255+
233256
## Summary
234257
235258
Objects are assigned and copied by reference. In other words, a variable stores not the "object value", but a "reference" (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object.

2-ui/4-forms-controls/3-events-change-input/article.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ For instance, the code below prevents all such events and shows what we are tryi
6262
</script>
6363
```
6464

65-
Technically, we can copy/paste everything. For instance, we can copy a file in the OS file manager, and paste it.
65+
Please note, that it's possible to copy/paste not just text, but everything. For instance, we can copy a file in the OS file manager, and paste it.
6666

67-
There's a list of methods [in the specification](https://www.w3.org/TR/clipboard-apis/#dfn-datatransfer) to work with different data types, read/write to the clipboard.
67+
That's because `clipboardData` implements `DataTransfer` interface, commonly used for drag'n'drop and copy/pasting. It's bit beyound our scope now, but you can find its methods [in the specification](https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface).
6868

69-
But please note that clipboard is a "global" OS-level thing. Most browsers allow read/write access to the clipboard only in the scope of certain user actions for the safety. Also it is forbidden to create "custom" clipboard events in all browsers except Firefox.
69+
```warn header="ClipboardAPI: user safety restrictions"
70+
The clipboard is a "global" OS-level thing. So most browsers allow read/write access to the clipboard only in the scope of certain user actions for the safety, e.g. in `onclick` event handlers.
71+
72+
Also it's forbidden to generate "custom" clipboard events with `dispatchEvent` in all browsers except Firefox.
73+
```
7074

7175
## Summary
7276

0 commit comments

Comments
 (0)