Skip to content

Commit f773836

Browse files
committed
Finished Proxy
1 parent 8e7f04f commit f773836

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

JS/JS-br.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,13 +1270,9 @@ test()
12701270
12711271
O código acime vai exibir `finish` antes de exibir `object`. Porque `await` espera pela funcão `sleep` `resolve`, mesmo se a sincronização de código estiver seguida, ele não executa antes do código assíncrono ser executado.
12721272
1273-
A vantagem do `async` e `await` comparado ao uso direto da `Promise` mente em manipular a cadeia de chamada do `then`, que pode produzir código claro e acurado.
1273+
A vantagem do `async` e `await` comparado ao uso direto da `Promise` mente em manipular a cadeia de chamada do `then`, que pode produzir código claro e acurado. A desvantagem é que uso indevido do `await` pode causar problemas de performance porque `await` bloqueia o código. Possivelmente o código assíncrono não depende do anterior, mas ele ainda precisa esperar o anterir ser completo, ocasionando perda de concorrência.
12741274
1275-
The above code will print `finish` before printing `object`. Because `await` waits for the `sleep` function `resolve`, even if the synchronization code is followed, it is not executed before the asynchronous code is executed.
1276-
1277-
The advantage of `async` and `await` compared to the direct use of `Promise` lies in handling the call chain of `then`, which can produce clear and accurate code. The downside is that misuse of `await` can cause performance problems because `await` blocks the code. Perhaps the asynchronous code does not depend on the former, but it still needs to wait for the former to complete, causing the code to lose concurrency.
1278-
1279-
Let's look at a code that uses `await`:
1275+
Vamos dar uma olhada em um código que usa `await`:
12801276
12811277
```js
12821278
var a = 0
@@ -1291,24 +1287,24 @@ a++
12911287
console.log('1', a) // -> '1' 1
12921288
```
12931289
1294-
You may have doubts about the above code, here we explain the principle:
1290+
Você pode ter dúvidas sobre o código acima, aqui nós explicamos o príncipio:
12951291
1296-
- First the function `b` is executed. The variable `a` is still 0 before execution `await 10`, Because the `Generators` are implemented inside `await` and `Generators` will keep things in the stack, so at this time `a = 0` is saved
1297-
- Because `await` is an asynchronous operation, `console.log('1', a)` will be executed first.
1298-
- At this point, the synchronous code is completed and asynchronous code is started. The saved value is used. At this time, `a = 10`
1299-
- Then comes the usual code execution
1292+
- Primeiro a função `b` é executada. A variável `a` ainda é zero antes da execução do `await 10`, porque os `Generators` são implementados dentro do `await` e `Generators` matém as coisas na pilha, então nesse momento `a = 0` é salvo
1293+
- Porque `await` é uma operação assíncrona, `console.log('1', a)` será executada primeiro.
1294+
- Nesse ponto, o código síncrono é completado e o código assíncrono é iniciado. O valor salvo é usado. Nesse instante, `a = 10`
1295+
- Então chega a execução usual do código
13001296
13011297
# Proxy
13021298
1303-
Proxy is a new feature since ES6. It can be used to define operations in objects:
1299+
Proxi é uma nova funcionalidade desde o ES6. Ele costuma ser usado para definir operações em objetos:
13041300
13051301
```js
13061302
let p = new Proxy(target, handler);
1307-
// `target` represents the object of need to add the proxy
1308-
// `handler` customizes operations in the object
1303+
// `target` representa o objeto que precisamos adicionar o proxy
1304+
// `handler` operações customizadas no objeto
13091305
```
13101306
1311-
Proxy can be handy for implementation of data binding and listening:
1307+
Proxy podem ser conveniente para implementação de data bindind e listening:
13121308
13131309
```js
13141310
let onWatch = (obj, setBind, getLogger) => {
@@ -1332,8 +1328,8 @@ let p = onWatch(obj, (v) => {
13321328
}, (target, property) => {
13331329
console.log(`Get '${property}' = ${target[property]}`);
13341330
})
1335-
p.a = 2 // bind `value` to `2`
1336-
p.a // -> Get 'a' = 2
1331+
p.a = 2 // liga `value` para `2`
1332+
p.a // -> obtém 'a' = 2
13371333
```
13381334
13391335
# Why 0.1 + 0.2 != 0.3

0 commit comments

Comments
 (0)