forked from javascript-tutorial/uk.javascript.info
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic DOM Node Properties (javascript-tutorial#260)
- Loading branch information
1 parent
a0446e4
commit 0925650
Showing
11 changed files
with
263 additions
and
263 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...1-document/05-basic-dom-node-properties/2-lastchild-nodetype-inline/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
Let's make a loop over `<li>`: | ||
Давайте зробимо цикл по `<li>`: | ||
|
||
```js | ||
for (let li of document.querySelectorAll('li')) { | ||
... | ||
} | ||
``` | ||
|
||
In the loop we need to get the text inside every `li`. | ||
У циклі нам потрібно отримати текст всередині кожного `li`. | ||
|
||
We can read the text from the first child node of `li`, that is the text node: | ||
Ми можемо прочитати текст з першого дочірнього вузла `li`, це текстовий вузол: | ||
|
||
```js | ||
for (let li of document.querySelectorAll('li')) { | ||
let title = li.firstChild.data; | ||
|
||
// title is the text in <li> before any other nodes | ||
// title -- це текст в <li> перед будь-якими іншими вузлами | ||
} | ||
``` | ||
|
||
Then we can get the number of descendants as `li.getElementsByTagName('li').length`. | ||
Тоді ми можемо отримати кількість нащадків як `li.getElementsByTagName('li').length`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
...document/05-basic-dom-node-properties/4-where-document-in-hierarchy/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
|
||
We can see which class it belongs by outputting it, like: | ||
Ми можемо побачити, якому класу він належить вивівши його, наприклад: | ||
|
||
```js run | ||
alert(document); // [object HTMLDocument] | ||
``` | ||
|
||
Or: | ||
Або: | ||
|
||
```js run | ||
alert(document.constructor.name); // HTMLDocument | ||
``` | ||
|
||
So, `document` is an instance of `HTMLDocument` class. | ||
Отже, `document` -- це екземпляр класу `HTMLDocument`. | ||
|
||
What's its place in the hierarchy? | ||
Яке його місце в ієрархії? | ||
|
||
Yeah, we could browse the specification, but it would be faster to figure out manually. | ||
Так, ми могли б переглянути специфікацію, але було б швидше з’ясувати вручну. | ||
|
||
Let's traverse the prototype chain via `__proto__`. | ||
Давайте пройдемо по ланцюгу прототипів через `__proto__`. | ||
|
||
As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents. | ||
Як відомо, методи класу знаходяться в `prototype` конструктора. Наприклад, `HTMLDocument.prototype` має методи документів. | ||
|
||
Also, there's a reference to the constructor function inside the `prototype`: | ||
Також є посилання на функцію конструктора всередині `prototype`: | ||
|
||
```js run | ||
alert(HTMLDocument.prototype.constructor === HTMLDocument); // true | ||
``` | ||
|
||
To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`: | ||
Щоб отримати назву класу як рядок, ми можемо використовувати `constructor.name`. Давайте зробимо це для всього прототипного ланцюга `document` аж до класу` Node`: | ||
|
||
```js run | ||
alert(HTMLDocument.prototype.constructor.name); // HTMLDocument | ||
alert(HTMLDocument.prototype.__proto__.constructor.name); // Document | ||
alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node | ||
``` | ||
|
||
That's the hierarchy. | ||
Це ієрархія. | ||
|
||
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally. | ||
Ми також можемо розглянути об’єкт за допомогою `console.dir(document)` і побачити ці назви, відкриваючи `__proto__`.Консоль браузера під капотом бере їх з `constructor`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.