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
3.We load `3.js`, then if there's no error -- do something else`(*)`.
216
+
No código acima:
217
+
1.Carregamos `1.js`, e depois, se não tiver nenhum erro.
218
+
2.Carregamos `2.js`, e depois, se não tiver nenhum erro.
219
+
3.Carregamos `3.js`, e depois, se não tiver nenhum erro -- faz outra coisa`(*)`.
220
220
221
-
As calls become more nested, the code becomes deeper and increasingly more difficult to manage, especially if we have a real code instead of`...`, that may include more loops, conditional statements and so on.
221
+
À medida em que as chamadas ficam mais aninhadas, o código vai ficando mais profundo e cada vez mais difícil de gerenciar, especialmente se nós tivermos um código real em vez de`...`, que pode incluir mais laços, condicionais e assim por diante.
222
222
223
-
That's sometimes called "callback hell" or "pyramid of doom."
223
+
Isso é às vezes chamado de "callback hell (inferno dos callbacks)" ou "pyramid of doom (pirâmide da perdição)."
The "pyramid" of nested calls grows to the right with every asynchronous action. Soon it spirals out of control.
251
+
A "pirâmide" de chamadas aninhadas cresce para a direita a cada ação assíncrona e rapidamente sai de controle.
252
252
253
-
So this way of coding isn't very good.
253
+
Então esse jeito de programar não é muito bom.
254
254
255
-
We can try to alleviate the problem by making every action a standalone function, like this:
255
+
Nós podemos tentar diminuir o problema fazendo cada ação ser uma função separada, assim:
256
256
257
257
```js
258
258
loadScript('1.js', step1);
@@ -279,17 +279,17 @@ function step3(error, script) {
279
279
if (error) {
280
280
handleError(error);
281
281
} else {
282
-
// ...continue after all scripts are loaded (*)
282
+
// ...continua depois que todos os scripts são carregados (*)
283
283
}
284
284
};
285
285
```
286
286
287
-
See? It does the same, and there's no deep nesting now because we made every action a separate top-level function.
287
+
Viu? Isso faz a mesma coisa, e não tem um aninhamento profundo agora porque nós fizemos cada ação em uma função separada no mesmo nível.
288
288
289
-
It works, but the code looks like a torn apart spreadsheet. It's difficult to read, and you probably noticed that one needs to eye-jump between pieces while reading it. That's inconvenient, especially if the reader is not familiar with the code and doesn't know where to eye-jump.
289
+
funciona, porém o código parece uma planilha dividida. É difícil de ler, e você provavelmente percebeu que precisamos pular entre as partes do código enquanto estamos lendo ele. Isso é inconveniente, especialmente se o leitor não estiver familiarizado com o código e não souber para onde pular.
290
290
291
-
Also, the functions named`step*`are all of single use, they are created only to avoid the "pyramid of doom." No one is going to reuse them outside of the action chain. So there's a bit of a namespace cluttering here.
291
+
Além disso, as funções chamadas`step*`são todas utilizadas apenas uma vez. Elas são criadas apenas pra evitar a "pirâmide da perdição." Ninguém vai reutilizá-las fora da cadeia de ações. Então tem um pouco de bagunça aqui.
292
292
293
-
We'd like to have something better.
293
+
Gostaríamos de ter algo melhor.
294
294
295
-
Luckily, there are other ways to avoid such pyramids. One of the best ways is to use "promises," described in the next chapter.
295
+
Felizmente, existem outras maneiras de evitar essas pirâmides. Uma das melhores maneiras é usar "promises (promessas)", descritas no próximo capítulo.
0 commit comments