document 계층구조 확인하기

lee jae hwan·2022년 8월 11일

브라우저

목록 보기
6/39
alert(document); // [object HTMLDocument]
alert(document.constructor.name); // HTMLDocument

document객체는 HTMLDocument클래스의 인스턴스다.

HTMLDocument클래스는 어떤 상위클래스를 상속할까?

alert(HTMLDocument.prototype.constructor.name); // HTMLDocument
alert(HTMLDocument.prototype.__proto__.constructor.name); // Document
alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node

HTMLDocument클래스 -> Document클래스 -> Node클래스 -> EventTarget클래스

document.firstChild를 사용하려면 Node클래스의 인스턴스여야 한다.

0개의 댓글