Skip to content

Class inheritance - #472

Merged
gabifs merged 2 commits into
javascript-tutorial:masterfrom
diogoosz:translate-class-inheritance
Nov 8, 2026
Merged

gabifs merged 2 commits into
javascript-tutorial:masterfrom
diogoosz:translate-class-inheritance

Conversation

@diogoosz

@diogoosz diogoosz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Tradução do artigo "Class inheritance" para o português, incluindo os 2 exercícios e a tradução do diagrama class-inheritance-rabbit-animal.svg.

Conforme comentado na #1.

Comment thread images.yml Outdated
"I love":
"text": "Eu amo"
"position": "center"
class-inheritance-rabbit-animal.svg:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O SVG class-inheritance-rabbit-animal.svg foi traduzido duas vezes: o texto foi editado direto no arquivo .svg e também foi adicionada esta entrada no images.yml. Como o SVG já não contém mais "methods of Animal", "methods of Rabbit" nem "properties of rabbit", as chaves desta entrada não batem com nada no arquivo, e a edição direta do SVG vai gerar conflito na próxima sincronização com o repositório original em inglês. O CLAUDE.md do projeto diz: "SVG text translations are defined in images.yml at repository root." Sugestão: reverter a alteração no .svg e manter só esta entrada no images.yml.

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="198" height="258" viewBox="0 0 198 258"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="inheritance" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="class-inheritance-rabbit-animal.svg"><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 128h179v28H11z"/><text id="methods-of-Rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="19" y="146">methods of Rabbit</tspan></text><text id="Rabbit.prototype" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="120">Rabbit.prototype</tspan></text><text id="rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="213">rabbit</tspan></text><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 21h179v28H11z"/><text id="methods-of-Animal" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="19" y="38">methods of Animal</tspan></text><text id="Animal.prototype" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="13">Animal.prototype</tspan></text><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 222h179v28H11z"/><path id="Line" fill="#C06334" fill-rule="nonzero" d="M70.5 167.5l7 14h-6v28h-2v-28h-6l7-14z"/><path id="Line-2" fill="#C06334" fill-rule="nonzero" d="M70.5 62.5l7 14h-6v28h-2v-28h-6l7-14z"/><text id="[[Prototype]]" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="80" y="86">[[Prototype]]</tspan></text><text id="[[Prototype]]-Copy" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="80" y="190">[[Prototype]]</tspan></text><text id="properties-of-rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="19" y="239">properties of rabbit</tspan></text></g></g></svg> No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="198" height="258" viewBox="0 0 198 258"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="inheritance" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="class-inheritance-rabbit-animal.svg"><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 128h179v28H11z"/><text id="methods-of-Rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="19" y="146">métodos de Rabbit</tspan></text><text id="Rabbit.prototype" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="120">Rabbit.prototype</tspan></text><text id="rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="213">rabbit</tspan></text><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 21h179v28H11z"/><text id="methods-of-Animal" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="19" y="38">métodos de Animal</tspan></text><text id="Animal.prototype" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="10" y="13">Animal.prototype</tspan></text><path id="Rectangle-1" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M11 222h179v28H11z"/><path id="Line" fill="#C06334" fill-rule="nonzero" d="M70.5 167.5l7 14h-6v28h-2v-28h-6l7-14z"/><path id="Line-2" fill="#C06334" fill-rule="nonzero" d="M70.5 62.5l7 14h-6v28h-2v-28h-6l7-14z"/><text id="[[Prototype]]" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="80" y="86">[[Prototype]]</tspan></text><text id="[[Prototype]]-Copy" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="80" y="190">[[Prototype]]</tspan></text><text id="properties-of-rabbit" fill="#AF6E24" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal"><tspan x="11" y="239">propriedades de rabbit</tspan></text></g></g></svg> No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O texto "propriedades de rabbit" (22 caracteres em PT Mono 14px, ~8,4px por caractere, cerca de 185px) foi movido para x="11", mas o retângulo vai de x=11 a x=190. O texto começa em cima da borda esquerda e termina por volta de x=196, passando da borda direita. "métodos de Animal/Rabbit" cabem; este não. Além disso, nenhum artigo referencia este SVG (grep por class-inheritance-rabbit-animal.svg só encontra o próprio arquivo), então a tradução não aparece em lugar nenhum. Os SVGs que o artigo usa (rabbit-animal-independent-animal.svg, animal-rabbit-extends.svg, this-super-loop.svg, super-homeobject-wrong.svg) só têm código. Dá para reverter este arquivo.

Como coelhos são animais, a classe `Rabbit` deveria ser baseada em `Animal`, ter acesso aos métodos de animal, para que coelhos possam fazer o que animais "genéricos" conseguem fazer.

The syntax to extend another class is: `class Child extends Parent`.
A sintaxe para estender outra classe é: `class Filha extends Pai`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class Child extends Parent virou class Filha extends Pai, e o mesmo aconteceu no Resumo (linhas 688-693: Filha.prototype.__proto__, Pai.prototype, "construtor de Filha", "método de Pai"). Isso traduz nomes de classe dentro de código, e o CLAUDE.md do projeto diz: "Don't translate code: You should not translate variable or function names". Os gêneros também não combinam ("Filha" é feminino e "Pai" é masculino). Sugestão: manter Child/Parent dentro dos trechos de código e traduzir só o texto ao redor.


````smart header="Arrow functions have no `super`"
As was mentioned in the chapter <info:arrow-functions>, arrow functions do not have `super`.
````smart header="Funções arrow não têm `super`"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Funções arrow" (aqui, nas linhas 160 e 242 e no Resumo, linha 701) não segue o termo que o resto do tutorial já usa: 1-js/02-first-steps/17-arrow-functions-basics tem o título "Funções seta, o básico" e 1-js/06-advanced-functions/12-arrow-functions usa "Arrow Functions (funções seta)". O CLAUDE.md também pede "avoid using foreign words". Sugestão: usar "funções seta" em todo o artigo.

@@ -611,17 +611,17 @@ rabbit.eat(); // Error calling super (because there's no [[HomeObject]])
*/!*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na linha 610, logo acima, o comentário // Error calling super (because there's no [[HomeObject]]) ficou em inglês. Diferente de // Unexpected super, que é a mensagem real do motor, a parte entre parênteses é uma explicação e deveria ser traduzida, por exemplo: // Erro ao chamar super (porque não existe [[HomeObject]]).

# Relógio estendido

We've got a `Clock` class. As of now, it prints the time every second.
Temos uma classe `Clock`. Até agora, ela imprime a hora a cada segundo.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"As of now" quer dizer "atualmente/por enquanto". "Até agora" passa a ideia de que algo vai mudar ou já mudou.

Suggested change
Temos uma classe `Clock`. Até agora, ela imprime a hora a cada segundo.
Temos uma classe `Clock`. Por enquanto, ela imprime a hora a cada segundo.

[js src="source.view/clock.js"]

Create a new class `ExtendedClock` that inherits from `Clock` and adds the parameter `precision` -- the number of `ms` between "ticks". Should be `1000` (1 second) by default.
Crie uma nova classe `ExtendedClock` que herda de `Clock` e adiciona o parâmetro `precision` -- o número de `ms` entre os "ticks". Deve ser `1000` (1 segundo) por padrão.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ticks" ficou em inglês. O CLAUDE.md do projeto pede "avoid using foreign words". Sugestão: "tiques" (ou "batidas").

class Rabbit extends Animal {
stop() {
setTimeout(() => super.stop(), 1000); // call parent stop after 1sec
setTimeout(() => super.stop(), 1000); // chama o stop do pai depois de 1seg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"1seg" não é uma abreviação padrão (o símbolo do SI é "s").

Suggested change
setTimeout(() => super.stop(), 1000); // chama o stop do pai depois de 1seg
setTimeout(() => super.stop(), 1000); // chama o stop do pai depois de 1 segundo

@diogoosz

diogoosz commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Obrigado pela revisão detalhada, @gabifs! Revertei o SVG editado à mão e removi a entrada órfã do images.yml (já que a imagem nem é referenciada pelo artigo). Também desfiz o "Filha"/"Pai" — voltei pra Child/Parent em todos os trechos de código, já que isso viola a regra de não traduzir identificadores (e nem fazia sentido com os gêneros). Troquei "Funções arrow" por "funções seta" (alinhando com os outros capítulos), traduzi o comentário explicativo que tinha ficado em inglês, e corrigi "1seg"→"1 segundo", "As of now"→"Por enquanto", e "ticks"→"tiques" no exercício.

@gabifs
gabifs merged commit d06fc4c into javascript-tutorial:master Nov 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants