Any script included in this way doesn't run in it's own context. Instead all scripts are executed within the context of the window that loaded them, meaning any objects or methods loaded in one script will be available in other scripts executed within the same window.
The order matters here, too. If file.js
was included first, any references to objects or functions defined in socket.io
would be undefined. That is, unless you have some sort of delayed execution mechanism in file.js
which waits until the rest of the document is loaded to execute.
And, of course, this also applies to inline scripts. For example:
<!-- defines myFunc -->
<script type="text/javascript" src="my.js"></script>
<script type="text/javascript">
myFunc(); // call myFunc
</script>