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
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -352,7 +352,7 @@ Usando `var` é mais provável error-prone, portanto ES6 introduziu uma nova pal
352
352
353
353
# Closure
354
354
355
-
The definition of closure is simple: function A returns a function B, and function B can access variables of function A, thus function B is called a closure.
355
+
A definição de closure é simples: a função A retorna a função B, e a função b consegue acessar as variáveis da função A, portanto a função B é chamada de closure.
356
356
357
357
```js
358
358
functionA() {
@@ -364,6 +364,8 @@ 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
368
+
367
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.
368
370
369
371
A classic interview question is using closures in loops to solve the problem of using `var` to define functions:
0 commit comments