Skip to content

Commit 3138bca

Browse files
committed
DOM Collections translated
1 parent 924a6fb commit 3138bca

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

2-ui/1-document/03-dom-navigation/article.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,54 +127,54 @@ elem.childNodes[elem.childNodes.length - 1] === elem.lastChild
127127
128128
A função `elem.hasChildNodes()` verifica se há algum nó filho.
129129
130-
### DOM collections
130+
### Coleções DOM
131131
132-
As we can see, `childNodes` looks like an array. But actually it's not an array, but rather a *collection* -- a special array-like iterable object.
132+
Como podemos ver, `childNodes` se parece com uma array. Mas, na verdade, não é uma array, mas sim uma *coleção* -- um objeto iterável semelhante a uma array.
133133
134-
There are two important consequences:
134+
Há duas implicações importantes:
135135
136-
1. We can use `for..of` to iterate over it:
136+
1. Podemos usar `for..of` para iterar sobre:
137137
```js
138138
for (let node of document.body.childNodes) {
139-
alert(node); // shows all nodes from the collection
139+
alert(node); // mostra todos os nós da coleção
140140
}
141141
```
142-
That's because it's iterable (provides the `Symbol.iterator` property, as required).
142+
Isso ocorre porque é iterável (fornece a propriedade `Symbol.iterator`, quando necessário).
143143
144-
2. Array methods won't work, because it's not an array:
144+
2. Métodos de array não funcionam, porque não é uma array:
145145
```js run
146-
alert(document.body.childNodes.filter); // undefined (there's no filter method!)
146+
alert(document.body.childNodes.filter); // undefined (não possui o método filter!)
147147
```
148148
149-
The first thing is nice. The second is tolerable, because we can use `Array.from` to create a "real" array from the collection, if we want array methods:
149+
A primeira implicação é boa. A segunda é tolerável, porque podemos usar `Array.from` para criar uma array "real" a partir da coleção, se quisermos métodos de array:
150150
151151
```js run
152-
alert( Array.from(document.body.childNodes).filter ); // now it's there
152+
alert( Array.from(document.body.childNodes).filter ); // function
153153
```
154154
155-
```warn header="DOM collections are read-only"
156-
DOM collections, and even more -- *all* navigation properties listed in this chapter are read-only.
155+
```warn header="Coleções DOM são somente leitura"
156+
Coleções DOM e muito mais -- *todas* as propriedades de navegação listadas neste capítulo são somente leitura.
157157
158-
We can't replace a child by something else by assigning `childNodes[i] = ...`.
158+
Não podemos substituir um filho através de uma atribuição: `childNodes[i] = ...`.
159159
160-
Changing DOM needs other methods. We will see them in the next chapter.
160+
São necessários outros métodos para alterar o DOM. Veremos no próximo capítulo.
161161
```
162162
163-
```warn header="DOM collections are live"
164-
Almost all DOM collections with minor exceptions are *live*. In other words, they reflect the current state of DOM.
163+
```warn header="Coleções DOM estão ativas"
164+
Quase todas as coleções DOM, com pequenas exceções, são *ativas*. Em outras palavras, elas refletem o estado atual do DOM.
165165
166-
If we keep a reference to `elem.childNodes`, and add/remove nodes into DOM, then they appear in the collection automatically.
166+
Se mantivermos uma referência ao `elem.childNodes` e adicionarmos nós no DOM, eles aparecerão automaticamente na coleção.
167167
```
168168
169-
````warn header="Don't use `for..in` to loop over collections"
170-
Collections are iterable using `for..of`. Sometimes people try to use `for..in` for that.
169+
````warn header="Não use `for..in` para iterar coleções"
170+
As coleções são iteráveis usando `for..of`. Às vezes as pessoas tentam usar `for..in` para isso.
171171
172-
Please, don't. The `for..in` loop iterates over all enumerable properties. And collections have some "extra" rarely used properties that we usually do not want to get:
172+
Por favor, não! O loop `for..in` itera sobre todas as propriedades enumeráveis. E as coleções têm algumas propriedades "extras" raramente usadas que, geralmente, não queremos obter:
173173
174174
```html run
175175
<body>
176176
<script>
177-
// shows 0, 1, length, item, values and more.
177+
// mostra: 0, 1, length, item, values...
178178
for (let prop in document.body.childNodes) alert(prop);
179179
</script>
180180
</body>

0 commit comments

Comments
 (0)