Is there a way to do functions and variable hoisting between source code present in different files? That is, something like
//Inside firstfile.js
foo === \"bar\
Separately-loaded Javascript sources can all affect the global context. Thus
window.foo = "bar";
in one source file will allow another source (loaded subsequently) to check:
if (window.foo === "bar") {
// do something
}
This has to work, or else it would not be possible to create something like all the popular Javascript frameworks.
The "this" keyword is only meaningful inside a function, and its value has nothing to do with the source file from which the function came (at least, nothing in any direct sense).
edit — I guess that the interesting thing here is the Javascript interpreter behavior that (to use the term in the question) "hoists" function declarations up before other code in a block being evaluated. That also is done on a script-by-script basis when the browser is loading them. Thus, function declarations in a script block are interpreted before other code in each block, but a single tag will be completely evaluated before the next
tag is loaded and evaluated.
Things get more complicated if you're using something like LabJS or enhance.js to load scripts, but I don't know of any context wherein you could rely on scripts "blending together" somehow unless you explicitly combine them at the server.