Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript initialized objects (and the dom)

What objects are created initially by compilers(?) of javascript?

I've been learning Io in order to understand prototyping languages. After doing a bit of research I've found the javascript 'Global Object'. What I can't seem to wrap my mind around is where the other built-in functions/prototypes/objects are coming from.

There is a print object and I have no clue where it was created. Was it created by the v8 engine I am using to run the javascript code?

And similarly, I'm a bit confused as to which objects are created in a browser initially. I understand that the browser creates a dom in javascript. For example, the document object. But what other objects are there?

Also, in Io it is possible to view all objects that have been allocated memory. This is accessed through the Lobby. Is there something similar in javascript?

like image 388
jaredlwong Avatar asked Aug 27 '26 13:08

jaredlwong


1 Answers

My favorite reference on javascript in a browser, global objects and DOM objects is MDN.

The browser creates a whole bunch of objects and makes them available for javascript access. They are created by the browser (not by the javascript engine as they aren't officially part of javascript), but the browser makes them accessible from javascript.

For example, the browser creates a document object, a window object which serves as the global object in the browser and adds a whole bunch of properties to the window object.

You can see a list of enumerable properties on the window object in your particular browser from this sample app: http://jsfiddle.net/jfriend00/nh39F/

Javascript, by itself, has some objects is creates just for it's own management of functionality. For example, there is usually a Math object that contains a bunch of math methods and a Date object that contains a bunch of date functionality.

like image 120
jfriend00 Avatar answered Aug 29 '26 03:08

jfriend00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!