DOM under the hood

Hello guys, I am confused about the DOM and have several questions. DOM is just specification for browsers developers that specifies necessary interfaces? The specification is implemented by browser internally in low-level language? Browser gives us host objects, constructed prototypal chain where EventTarget is root class from which descendant classes like Element, Node, HTMLElement inherits? How it is possible that document.querySelector('div') returns element and that element has [[Prototype]] property with constructor function HTMLDivElement(), but I can't use that constructor directly like const div = new HTMLDivElement(). Interface in programming world is something like blueprint that only says which methods, properties should something have to implement this interface? So every class, object, method, etc. is constructed in browser internally in some low-level language and we get it accessible through javascript? I am just curious how it works under the hood. Thank you for every helpful resource or explanation.
4 Replies
michTheBrandofficial
From how you explained the DOM, you have a lot of knowledge of it. Yes probably that is just how it is.
ἔρως
ἔρως16mo ago
the "dom" is the document itself which document? it kinda doesn't matter it doesn't have to be a browser, as php has a dom interface as well
DOM is just specification for browsers developers that specifies necessary interfaces? The specification is implemented by browser internally in low-level language? Browser gives us host objects, constructed prototypal chain where EventTarget is root class from which descendant classes like Element, Node, HTMLElement inherits? How it is possible that document.querySelector('div') returns element and that element has [[Prototype]] property with constructor function HTMLDivElement(), but I can't use that constructor directly like const div = new HTMLDivElement().
that's a good question netscape 2 started it! but you can't do const div = new HTMLDivElement() because it isn't/doesn't have a constructor however, it extends the HTMLElement prototype, which extends the Element prototype, which extends the Object prototype i might have missed 1 or more prototypes in the middle
Interface in programming world is something like blueprint that only says which methods, properties should something have to implement this interface?
javascript is a prototype language, and interfaces are something for typescript
ἔρως
ἔρως16mo ago
https://www.typescriptlang.org/docs/handbook/2/objects.html <-- you can read about typescript interfaces here
Documentation - Object Types
How TypeScript describes the shapes of JavaScript objects.
ἔρως
ἔρως16mo ago
So every class, object, method, etc. is constructed in browser internally in some low-level language and we get it accessible through javascript?
if you're talking about the dom, kinda there's new Image() but nearly everything else? yes i mean, it isn't "some low-level language", it's "machine code" and the level above is assembly, and above it is (usually) c++
Want results from more Discord servers?
Add your server