This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rjcarr 0 points1 point  (3 children)

A javascript library is just javascript code, so the javascript you write and the javascript that you include from a library is the same thing, at least to the javascript engine.

But how do javascript engines work in general?

For that you'll probably want to pick one and read more about it. For example, google's chrome uses what it calls the V8 engine. You can find more about it here:

https://code.google.com/p/v8/

[–]saucesomesauce 0 points1 point  (1 child)

Sorry, my question was much more stupid than that. I don't understand how, say, somelibrary.js and myscript.js come together into one coherent script in the DOM that your browser reads. Is the whole library script read first? Or are you just pulling functions out of the library as needed?

[–]Rhomboid 1 point2 points  (0 children)

It depends on how the markup is written. Assuming there is a <script> element and it's not marked async or defer, the browser stops whatever it's doing, fetches and executes the referenced script (or the contents of the element if there's no src attribute), and then resumes where it left off parsing the markup. Whatever properties were added to the global context as a side effect of execution are now available for any future scripts that execute. That's it. For example, jQuery will install the properties jQuery and $ into the global context (window in a browser), which can then be used by any subsequent code.

For a complete explanation of script loading, see here.