Repository navigation
The old "var" - #477
The old "var"#477diogoosz wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
||
| *!* | ||
| alert(test); // ReferenceError: test is not defined | ||
| alert(test); // ReferenceError: test não está definido |
There was a problem hiding this comment.
The translated error message here is not what the engine prints. Running this example shows ReferenceError: test is not defined, so readers will see different text from the comment. It also clashes with the SyntaxError messages in this same file (lines 96 and 234), which stay in English, and with the rest of the repo, which keeps is not defined.
| alert(test); // ReferenceError: test não está definido | |
| alert(test); // ReferenceError: test is not defined |
|
|
||
| sayHi(); | ||
| alert(phrase); // ReferenceError: phrase is not defined | ||
| alert(phrase); // ReferenceError: phrase não está definido |
There was a problem hiding this comment.
Same problem as line 55: the engine prints ReferenceError: phrase is not defined, not translated text.
| alert(phrase); // ReferenceError: phrase não está definido | |
| alert(phrase); // ReferenceError: phrase is not defined |
|
|
||
| *!*+*/!*function() { | ||
| alert("Unary plus starts the expression"); | ||
| alert("Operador unário de adição inicia a expressão"); |
There was a problem hiding this comment.
"Unary plus" means the unary + operator, not addition. "Operador unário de adição" gets the concept wrong. The repo already uses "mais unário" (see 99-js-misc/05-bigint).
| alert("Operador unário de adição inicia a expressão"); | |
| alert("Operador mais unário inicia a expressão"); |
| ``` | ||
|
|
||
| As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript, blocks had no Lexical Environments, and `var` is a remnant of that. | ||
| Como podemos ver, `var` atravessa o `if`, o `for` ou outros blocos de código. Isso acontece porque, há muito tempo, no JavaScript os blocos não tinham Ambientes Léxicos, e `var` é um resquício disso. |
There was a problem hiding this comment.
Terminology does not match the repo. "Lexical Environment" stays in English throughout the tutorial (about 70 times, including the closure chapter this text refers back to). Writing "Ambientes Léxicos" here breaks the link with that chapter. Suggest: os blocos não tinham Lexical Environments.
| Então, os parênteses em torno da função são um truque para mostrar ao JavaScript que a função é criada no contexto de outra expressão, e, portanto, é uma Expressão de Função: ela não precisa de nome e pode ser chamada imediatamente. | ||
|
|
||
| There exist other ways besides parentheses to tell JavaScript that we mean a Function Expression: | ||
| Existem outras formas, além dos parênteses, de dizer ao JavaScript que queremos dizer uma Expressão de Função: |
There was a problem hiding this comment.
This copies "we mean" too literally, and "dizer ... que queremos dizer" repeats the verb.
| Existem outras formas, além dos parênteses, de dizer ao JavaScript que queremos dizer uma Expressão de Função: | |
| Existem outras formas, além dos parênteses, de indicar ao JavaScript que se trata de uma Expressão de Função: |
|
|
||
| 1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function. | ||
| 2. `var` declarations are processed at function start (script start for globals). | ||
| 1. As variáveis `var` não têm escopo de bloco, sua visibilidade tem escopo na função atual, ou global, se declaradas fora de uma função. |
There was a problem hiding this comment.
"sua visibilidade tem escopo na função atual" reads awkwardly.
| 1. As variáveis `var` não têm escopo de bloco, sua visibilidade tem escopo na função atual, ou global, se declaradas fora de uma função. | |
| 1. As variáveis `var` não têm escopo de bloco: sua visibilidade fica restrita à função atual, ou é global, se declaradas fora de uma função. |
Tradução do artigo "The old var" para o português.
Conforme comentado na #1.