Skip to content

Commit 79b6e54

Browse files
committed
UPDATE
1 parent 32612cb commit 79b6e54

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

JS/JS-br.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,11 @@ console.log(b.age) // 2
520520
521521
A partir do exemplo acima, nós podemos ver que se você assinar um objeto para uma variável, então os valores dos dois vão ter a mesma referência, um muda o outro muda adequadamente.
522522
523-
From the above example, we can see that if you assign an object to a variable, then the values of both will be the same reference, one changes, the other changes accordingly.
523+
Geralmente, nós não queremos que tal problema apareça durante o desensolvimento, portanto podemos usar a cópia rasa para resolver esse problema.
524524
525-
Usually, we don't want such problem to appear during development, thus we can use shallow copy to solve this problem.
525+
## Cópia rasa
526526
527-
## Shallow copy
528-
529-
Firstly we can solve the problem by `Object.assign`:
527+
Primeiramente podemos resolver o problema através do `Object.assign`:
530528
```js
531529
let a = {
532530
age: 1
@@ -536,7 +534,7 @@ a.age = 2
536534
console.log(b.age) // 1
537535
```
538536
539-
Certainly, we can use the spread operator (...) to solve the problem:
537+
Certamente, podemos usar o spread operator (...) para resolver o problema:
540538
```js
541539
let a = {
542540
age: 1
@@ -546,7 +544,7 @@ a.age = 2
546544
console.log(b.age) // 1
547545
```
548546
549-
Usually, shallow copy can solve most problems, but we need deep copy when encountering the following situation:
547+
Geralmente, a cópia rasa pode resolver a maioria dos problemas, mas precisamos da cópia profunda quando encontrado a seguinte situação:
550548
```js
551549
let a = {
552550
age: 1,
@@ -558,11 +556,11 @@ let b = {...a}
558556
a.jobs.first = 'native'
559557
console.log(b.jobs.first) // native
560558
```
561-
The shallow copy only solves the problem of the first layer. If the object contains objects, then it returns to the beginning topic that both values share the same reference. To solve this problem, we need to introduce deep copy.
559+
A cópia rasa resolve apenas o problema na primeira camada. Se o objeto contém objetos, então ele retorna para o topico inicial que os dois valores compartilham a mesma referência. Para resolver esse problema, precisamos introduzir a cópia profunda.
562560
563-
## Deep copy
561+
## Cópia profunda
564562
565-
The problem can usually be solved by `JSON.parse(JSON.stringify(object))`
563+
O problema pode geralmente ser resolvido por `JSON.parse(JSON.stringify(object))`
566564
567565
```js
568566
let a = {
@@ -576,10 +574,10 @@ a.jobs.first = 'native'
576574
console.log(b.jobs.first) // FE
577575
```
578576
579-
But this method also has its limits:
580-
* ignore `undefined`
581-
* unable to serialize function
582-
* unable to resolve circular references in an object
577+
Mas esse método também tem seus limites:
578+
* ignora `undefined`
579+
* incapaz de serializar função
580+
* incapaz de resolver referência circular de um objeto
583581
```js
584582
let obj = {
585583
a: 1,

0 commit comments

Comments
 (0)