Skip to content

Commit 52552fa

Browse files
committed
Merge pull request braziljs#323 from ericdouglas/master
Adiciona tradução de exercício cap.10
2 parents 73510ba + 32631cb commit 52552fa

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

chapters/10-modulos.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,19 @@ console.log(month.number("November"));
388388

389389
Ele vai seguir o módulo weekDay praticamente por inteiro. Uma função anônima, chamada imediatamente, encapsula a variável que contém o array de nomes, assim como as duas funções que precisam ser exportadas. As funções são colocadas em um objeto. A interface de objeto retornada é armazenada na variável `month`.
390390

391-
### Circular dependencies
391+
### Dependências circulares
392392

393-
A tricky subject in dependency management is circular dependencies, where module A depends on B, and B also depends on A. Many module systems simply forbid this. CommonJS allows a limited form of this, where it works as long as the modules do not replace their default exports object with another value, and only start accessing each other’s interface after they finish loading.
393+
Um assunto complicado na gestão de dependências é o de dependências circulares, onde módulo A depende do módulo B, e B também depende do módulo A. Muitos sistemas simplesmente proibem isso. CommonJS permite uma forma limitada disso, onde isso funciona se os módulos não trocarem seus objetos exportados por padrão com outro valor, e somente começam a acessar a interface um do outro após terem finalizados seus carregamentos.
394394

395-
Can you think of a way in which support for this feature could be implemented? Look back to the definition of require, and consider what the could would have to do to allow this.
395+
Você pode pensar em algo que dê suporte para essa funcionalidade ser implementada? Olhe anteriormente a definição de `require`, e considere o quê você deve fazer para permitir isso.
396396

397-
The trick is to add the exports object created for a module to require's cache before actually running the module. This means the module will not yet have had a chance to override module.exports, so we do not know whether it may want to export some other value. After loading, the cache object is overridden with module.exports, which may be a different value.
397+
O segredo é adicionar o objeto `exports` criado por um módulo para requisitar o cache antes de rodar o módulo de fato. Isso significa que o módulo não teria tido ainda uma chance de sobrescrever `module.exports`, então não sabemos se ele deseja exportar outro valor. Depois de carregar, o objeto cache é sobrescrito com `module.exports`, que pode ser um valor diferente.
398398

399-
But if, in the course of loading the module, a second module is loaded that asks for the first module, its default exports object, likely still empty at this point, will be in the cache, and the second module will receive a reference to it. If it doesn’t try to do anything with the object until the first module has finished loading, things will work.
399+
Mas se, no curso de carregar o módulo, um segundo módulo é carregado e solicita o primeiro módulo, seu objeto `exports` padrão, ainda vazio até este ponto, vai estar no cache, e o segundo módulo vai receber uma referência dele. Se ele não tentar fazer nada com o objeto até que o segundo módulo tenha terminado seu carregamento, as coisas vão funcionar.
400400

401-
### A return to electronic life
401+
### Um retorno a vida eletrônica
402402

403-
Hoping that Chapter 7 is still somewhat fresh in your mind, think back to the system designed in that chapter and come up with a separation into modules of the code. To refresh your memory, these are the functions and types defined in that chapter, in order of appearance.
403+
Esperando que o capítulo 7 ainda esteja um pouco fresco em sua mente, pense novamente no sistema projetado neste capítulo e elabore um separação em módulo para o código. Para refrescar sua memória, essas são as funções e tipos definidos naquele capítulo, em ordem de aparição.
404404

405405
- Point
406406
- Grid
@@ -421,13 +421,13 @@ Hoping that Chapter 7 is still somewhat fresh in your mind, think back to the sy
421421
- SmartPlantEater
422422
- Tiger
423423

424-
Do not exaggerate and create too many modules. A book that starts a new chapter for every page would probably get on your nerves, if only because of all the space wasted on titles. Similarly, having to open ten files to read a tiny project isn’t helpful. Aim for three to five modules.
424+
Não exagere em criar muitos módulos. Um livro que começa um novo capítulo para cada página provavelmente vai te deixar nervoso, por todo espaço perdido com os títulos. De forma similar, ter que abrir dez arquivos para ler um pequeno projeto não é útil. Vise por três ou cinco módulos.
425425

426-
You can choose to have some functions become internal to their module, and thus inaccessible to other modules.
426+
Você pode escolher ter algumas funções internas ao módulo, e então inacessíveis a outros módulos.
427427

428-
There is no single correct solution here. Module organization is largely a matter of taste.
428+
Não existe uma única solução correta aqui. Organização de módulos é meramente uma questão de gosto.
429429

430-
Here is what I came up with. I’ve put parentheses around internal functions.
430+
Aqui está o que eu fiz. Coloquei parenteses em torno de funções internas.
431431

432432
- Module "grid"
433433
+ Point
@@ -455,8 +455,6 @@ Here is what I came up with. I’ve put parentheses around internal functions.
455455
+ SmartPlantEater
456456
+ Tiger
457457

458-
I have re-exported the directions array from the grid module from world, so that modules built on that (the ecosystems) don’t have to know or worry about the existence of the grid module.
459-
460-
I also duplicated two generic and tiny helper values (randomElement and Wall) since they are used as internal details in different contexts, and do not belong in the interfaces for these modules.
461-
458+
Eu reexportei o array `directions` do módulo `grid` para `world`, então módulos criados com eles (`ecosystems`) não precisam de saber ou se preocupar da existência do módulo `grid`.
462459

460+
Eu também dupliquei dois valores minúsculos e genéricos (`randomElement` e `Wall`) pois eles são usados como detalhes internos em contextos diferentes, e não pertencem nas interfaces destes módulos.

0 commit comments

Comments
 (0)