|
1 | 1 |
|
2 | | -We can see which class it belongs by outputting it, like: |
| 2 | +Possiamo visualizzare a quale classe appartiene in questo modo: |
3 | 3 |
|
4 | 4 | ```js run |
5 | 5 | alert(document); // [object HTMLDocument] |
6 | 6 | ``` |
7 | 7 |
|
8 | | -Or: |
| 8 | +Oppure: |
9 | 9 |
|
10 | 10 | ```js run |
11 | 11 | alert(document.constructor.name); // HTMLDocument |
12 | 12 | ``` |
13 | 13 |
|
14 | | -So, `document` is an instance of `HTMLDocument` class. |
| 14 | +Quindi `document` è un'istanza della classe `HTMLDocument`. |
15 | 15 |
|
16 | | -What's its place in the hierarchy? |
| 16 | +Qual è il suo posto nella gerarchia DOM? |
17 | 17 |
|
18 | | -Yeah, we could browse the specification, but it would be faster to figure out manually. |
| 18 | +Certo, potremmo sfogliare la specifica, ma sarebbe più veloce scoprirlo manualmente. |
19 | 19 |
|
20 | | -Let's traverse the prototype chain via `__proto__`. |
| 20 | +Attraversiamo la catena dei prototipi tramite `__proto__`. |
21 | 21 |
|
22 | | -As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents. |
| 22 | +Come sappiamo i metodi di una classe sono nel `prototype` del costruttore. Per esempio `HTMLDocument.prototype` ha i metodi per i documenti. |
23 | 23 |
|
24 | | -Also, there's a reference to the constructor function inside the `prototype`: |
| 24 | +C'è inoltre un riferimento al costruttore all'interno di `prototype`: |
25 | 25 |
|
26 | 26 | ```js run |
27 | 27 | alert(HTMLDocument.prototype.constructor === HTMLDocument); // true |
28 | 28 | ``` |
29 | 29 |
|
30 | | -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`: |
| 30 | +Per ricavare la stringa con il nome della classe possiamo usare `constructor.name`. Facciamolo per l'intera catena prototipale `document` fino alla classe` Node`: |
31 | 31 |
|
32 | 32 | ```js run |
33 | 33 | alert(HTMLDocument.prototype.constructor.name); // HTMLDocument |
34 | 34 | alert(HTMLDocument.prototype.__proto__.constructor.name); // Document |
35 | 35 | alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node |
36 | 36 | ``` |
37 | 37 |
|
38 | | -That's the hierarchy. |
| 38 | +Questa è la gerachia. |
39 | 39 |
|
40 | | -We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally. |
| 40 | +Potremmo anche esaminare l'oggetto usando `console.dir(document)` e visualizzare gli stessi nomi aprendo `__proto__`. La console li ricava internamente da `constructor`. |
0 commit comments