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
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -364,11 +364,9 @@ function A() {
364
364
}
365
365
```
366
366
367
-
Se você estiver se perguntando por que a função B também consegue se referenciar as variáveis da função A enquanto a função A
367
+
Se você estiver se perguntando por que a função B também consegue se referenciar as variáveis da função A enquanto a função A aparece a partir da stack de chamadas? Porque as variáveis na função A são guardadas na pilha nesse momento. O motor atual do JS consegue indentificar quais variáveis precisam ser salvas na heap e quais precisam ser salvas na stack por análise de fuga.
368
368
369
-
Are you wondering why function B can also refer to variables in function A while function A has been popped up from the call stack? Because variables in function A are stored on the heap at this time. The current JS engine can identify which variables need to be stored on the heap and which need to be stored on the stack by escape analysis.
370
-
371
-
A classic interview question is using closures in loops to solve the problem of using `var` to define functions:
369
+
Uma pergunta classica de entrevista é usando closure em loops para resolver o problema de usar `var` para definir funções:
372
370
373
371
```js
374
372
for ( var i=1; i<=5; i++) {
@@ -378,9 +376,9 @@ for ( var i=1; i<=5; i++) {
378
376
)
379
377
```
380
378
381
-
First of all, all loops will be executed completely because`setTimeout`is an asynchronous function, and at that time `i`is 6, so it will print a bunch of 6.
379
+
Em primeirio lugar, todos os loops vão ser executados completamente porque`setTimeout`é uma função assíncrona, e nesse momento `i`é 6, então isso vai exibir um bando de 6.
382
380
383
-
There are three solutions,closure is the first one:
381
+
Existe três soluções, closure é a primeira:
384
382
385
383
```js
386
384
for (var i =1; i <=5; i++) {
@@ -392,7 +390,7 @@ for (var i = 1; i <= 5; i++) {
392
390
}
393
391
```
394
392
395
-
The second one is to make use of the third parameter of`setTimeout`:
393
+
A segunda é fazer o uso do terceiro parâmetro do`setTimeout`:
396
394
397
395
```js
398
396
for ( var i=1; i<=5; i++) {
@@ -402,7 +400,7 @@ for ( var i=1; i<=5; i++) {
402
400
}
403
401
```
404
402
405
-
The third is to define`i`using`let`:
403
+
A terceira é definir o`i`usando`let`:
406
404
407
405
```js
408
406
for ( let i=1; i<=5; i++) {
@@ -412,11 +410,11 @@ for ( let i=1; i<=5; i++) {
412
410
}
413
411
```
414
412
415
-
For`let`, it will create a block-level scope, which is equivalent to:
413
+
Para`let`, ele vai criar um escopo de block-level, do qual é equivalente a:
0 commit comments