Skip to content

Commit

Permalink
Initialized Closure translation
Browse files Browse the repository at this point in the history
  • Loading branch information
lksilva committed Aug 27, 2018
1 parent 5fe3909 commit 4621216
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion JS/JS-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Usando `var` é mais provável error-prone, portanto ES6 introduziu uma nova pal

# Closure

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.
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.

```js
function A() {
Expand All @@ -364,6 +364,8 @@ function A() {
}
```

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

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.

A classic interview question is using closures in loops to solve the problem of using `var` to define functions:
Expand Down

0 comments on commit 4621216

Please sign in to comment.