You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JS/JS-br.md
+13-17Lines changed: 13 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1270,13 +1270,9 @@ test()
1270
1270
1271
1271
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.
1272
1272
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.
1274
1274
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`:
1280
1276
1281
1277
```js
1282
1278
var a =0
@@ -1291,24 +1287,24 @@ a++
1291
1287
console.log('1', a) // -> '1' 1
1292
1288
```
1293
1289
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:
1295
1291
1296
-
- First the function`b`is executed. The variable`a`is still 0 before execution `await10`, 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 `await10`, 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
1300
1296
1301
1297
# Proxy
1302
1298
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:
1304
1300
1305
1301
```js
1306
1302
let p =newProxy(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
1309
1305
```
1310
1306
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:
1312
1308
1313
1309
```js
1314
1310
letonWatch= (obj, setBind, getLogger) => {
@@ -1332,8 +1328,8 @@ let p = onWatch(obj, (v) => {
0 commit comments