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
4 changes: 2 additions & 2 deletions 1-js/05-data-types/12-json/1-serialize-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Turn the object into JSON and back
# Converta o objeto em JSON e de volta para objeto

Turn the `user` into JSON and then read it back into another variable.
Transforme o `user` em JSON e depois leia-o de volta em outra variável.

```js
let user = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ alert( JSON.stringify(meetup, function replacer(key, value) {
*/
```

Here we also need to test `key==""` to exclude the first call where it is normal that `value` is `meetup`.
Aqui também precisamos testar `key==""` para excluir a primeira chamada, em que é normal que `value` seja `meetup`.

14 changes: 7 additions & 7 deletions 1-js/05-data-types/12-json/2-serialize-event-circular/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Exclude backreferences
# Excluir referências circulares

In simple cases of circular references, we can exclude an offending property from serialization by its name.
Em casos simples de referências circulares, podemos excluir uma propriedade problemática da serialização pelo seu nome.

But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
Mas às vezes não podemos simplesmente usar o nome, já que ele pode ser usado tanto em referências circulares quanto em propriedades normais. Então podemos verificar a propriedade pelo seu valor.

Write `replacer` function to stringify everything, but remove properties that reference `meetup`:
Escreva uma função `replacer` para transformar tudo em string, mas removendo propriedades que referenciam `meetup`:

```js run
let room = {
Expand All @@ -22,16 +22,16 @@ let meetup = {
};

*!*
// circular references
// referências circulares
room.occupiedBy = meetup;
meetup.self = meetup;
*/!*

alert( JSON.stringify(meetup, function replacer(key, value) {
/* your code */
/* seu código */
}));

/* result should be:
/* o resultado deve ser:
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
Expand Down
Loading