Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/01-hello-world/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Então, primeiro, vamos ver como anexar um script a uma página. Para ambientes

## A tag "script"

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

Por exemplo:

Expand Down
24 changes: 0 additions & 24 deletions 1-js/04-object-basics/01-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,6 @@ let user = {
```
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.

````smart header="Objeto com const pode ser alterado"
Por favor, note: um objeto declarado como `const` *pode* ser modificado.

Por exemplo:

```js run
const user = {
name: "John"
};

*!*
user.name = "Pete"; // (*)
*/!*

alert(user.name); // Pete
```

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.

A `const` dará um erro apenas se tentarmos mudar `user=...` como um todo.

Há outra forma para tornar constantes as propriedades de um objeto, que iremos ver mais adiante no capítulo <info:property-descriptors>.
````

## Parênteses retos

Para propriedades com múltiplas palavras, o acesso por ponto não funciona:
Expand Down
25 changes: 24 additions & 1 deletion 1-js/04-object-basics/02-object-copy/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ admin.name = 'Pete'; // changed by the "admin" reference
alert(*!*user.name*/!*); // 'Pete', changes are seen from the "user" reference
```


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.

## Comparison by reference
Expand Down Expand Up @@ -230,6 +229,30 @@ To fix that, we should use the cloning loop that examines each value of `user[ke

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).

```smart header="Const objects can be modified"
An important "side effect" of storing objects as references is that an object declared as `const` *can* be modified.

For instance:

```js run
const user = {
name: "John"
};

*!*
user.name = "Pete"; // (*)
*/!*

alert(user.name); // Pete
```

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.

In other words, the `const user` gives an error only if we try to set `user=...` as a whole, and that's all.

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>.
```

## Summary

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.
Expand Down
10 changes: 7 additions & 3 deletions 2-ui/4-forms-controls/3-events-change-input/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ For instance, the code below prevents all such events and shows what we are tryi
</script>
```

Technically, we can copy/paste everything. For instance, we can copy a file in the OS file manager, and paste it.
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.

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.
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).

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.
```warn header="ClipboardAPI: user safety restrictions"
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.

Also it's forbidden to generate "custom" clipboard events with `dispatchEvent` in all browsers except Firefox.
```

## Summary

Expand Down