Repository navigation
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
||
| // call it | ||
| work(); // what will it show? | ||
| // a chama |
There was a problem hiding this comment.
// a chama (for "call it") reads as "the flame" in Portuguese — ambiguous comment. Suggest // chama a função or // chamando-a.
| A explicação técnica aprofundada vem a seguir. | ||
|
|
||
| As far as I'd like to avoid low-level language details, any understanding without them would be lacking and incomplete, so get ready. | ||
| Por mais que eu gostaria de evitar detalhes de baixo nível da linguagem, qualquer entendimento sem eles ficaria incompleto e deficiente, então se prepare. |
There was a problem hiding this comment.
Grammar: "Por mais que" requires the subjunctive — "Por mais que eu gostasse de evitar..." (not "gostaria").
| Como você pôde ver -- não existe essa variável! Em teoria, ela deveria ser acessível, mas o motor a otimizou e removeu. | ||
|
|
||
| That may lead to funny (if not such time-consuming) debugging issues. One of them -- we can see a same-named outer variable instead of the expected one: | ||
| Isso pode levar a problemas de depuração engraçados (se não tão demorados). Um deles -- podemos ver uma variável externa de mesmo nome em vez da esperada: |
There was a problem hiding this comment.
Meaning lost: original "funny (if not such time-consuming)" = "would be funny if they weren't so time-consuming". "(se não tão demorados)" reads as "if not so slow". Suggest: "problemas de depuração engraçados (se não fossem tão demorados)".
| @@ -1,12 +1,12 @@ | |||
| For the second parentheses to work, the first ones must return a function. | |||
| Para o segundo parênteses funcionar, o primeiro precisa retornar uma função. | |||
There was a problem hiding this comment.
Number agreement: "parênteses" is plural. Suggest "Para os segundos parênteses funcionarem, os primeiros precisam retornar uma função." (or "o segundo par de parênteses ... o primeiro").
| text: "Ambiente Léxico" | ||
| position: left | ||
| "of makeCounter() call": | ||
| text: "da chamada de makeCounter()" |
There was a problem hiding this comment.
"da chamada de makeCounter()" (27 chars) is ~6 chars longer than "of makeCounter() call" (21) and is left-anchored at x=275 in closure-makecounter.svg / lexenv-nested-makecounter-2.svg (PT Mono 12px ≈ 7.2px/char → ends ≈ x=469, past where the right-aligned "Ambiente Léxico global" starts at x=461). Please render to check it does not collide with the diagram/arrows; a shorter label like "de makeCounter()" would avoid it.
| Existe um termo geral de programação, "closure", que os desenvolvedores geralmente deveriam conhecer. | ||
|
|
||
| A [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) is a function that remembers its outer variables and can access them. In some languages, that's not possible, or a function should be written in a special way to make it happen. But as explained above, in JavaScript, all functions are naturally closures (there is only one exception, to be covered in <info:new-function>). | ||
| Uma [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) é uma função que lembra suas variáveis externas e consegue acessá-las. Em algumas linguagens, isso não é possível, ou uma função precisa ser escrita de uma forma especial pra isso acontecer. Mas, como explicado acima, no JavaScript, todas as funções são naturalmente closures (existe só uma exceção, que será coberta em <info:new-function>). |
There was a problem hiding this comment.
Inconsistent: line 145 switched the PRNG link to pt.wikipedia, but this closure link stays on en.wikipedia. pt.wikipedia has the article: https://pt.wikipedia.org/wiki/Clausura_(ci%C3%AAncia_da_computa%C3%A7%C3%A3o)
| Então, `counter.[[Environment]]` tem a referência ao Ambiente Léxico `{count: 0}`. É assim que a função lembra onde foi criada, não importa onde seja chamada. A referência `[[Environment]]` é definida uma vez e para sempre no momento da criação da função. | ||
|
|
||
| Later, when `counter()` is called, a new Lexical Environment is created for the call, and its outer Lexical Environment reference is taken from `counter.[[Environment]]`: | ||
| Mais tarde, quando `counter()` é chamada, um novo Ambiente Léxico é criado para a chamada, e sua referência de Ambiente Léxico externo é pega de `counter.[[Environment]]`: |
There was a problem hiding this comment.
"é pega de" is colloquial participle; for technical prose prefer "é obtida de counter.[[Environment]]".
| --- | ||
|
|
||
| # Filter through function | ||
| # Filtra através de uma função |
There was a problem hiding this comment.
Title verb form inconsistent with sibling task titles (e.g. "Ordenar por campo"). Suggest "Filtrar através de uma função".
| Para clareza, a explicação é dividida em várias etapas. | ||
|
|
||
| ### Step 1. Variables | ||
| ### Passo 1. Variáveis |
There was a problem hiding this comment.
Terminology mismatch: line 159 says "várias etapas" but headings use "Passo 1/2/3/4". Pick one (e.g. "Etapa 1. Variáveis" or "dividida em vários passos").
Tradução do artigo "Variable scope, closure" para o português, incluindo os 10 exercícios e as 13 imagens traduzidas (closure-function-declaration.svg, closure-variable-phrase.svg, lexical-environment-global.svg, lexical-environment-global-2.svg, lexical-environment-global-3.svg, lexical-environment-simple.svg, closure-makecounter.svg, closure-makecounter-nested-call-2.svg, lexenv-nested-makecounter-2.svg, lexenv-nested-makecounter-6.svg, lexenv-makearmy-empty.svg, lexenv-makearmy-for-fixed.svg, lexenv-makearmy-while-fixed.svg).
Conforme comentado na #1.