4 ms·
> Global variables are basically instance variables on the > process itself. Not in JS. See my response to ww520 below.
by bzbarsky 15y ago
> Global variables are basically instance variables on the
> process itself.
Not in JS. See my response to ww520 below.
- fennecfoxen 15y agoAh, I see what you're talking about. Seems like jesseedhillon was expecting that Node works like a browser: there's a lot of backend code in another language that handles the HTTP request, and then forks it over to a little JavaScript, and each request gets a new global scope. It's not like that. There's a teeny bit of C-based backend code; it's the JavaScript part that controls alll the interesting stuff like opening sockets and parsing HTTP headers and the like to determine a request. In a single process, with a single global object, with lots of asynchronous I/O. Node is JavaScript as a first-class programming language, not subservient to the DOM.
- bzbarsky 15y agoThis has nothing to do with the DOM. There are existing server-side JS deployments that have no DOM, but do create separate globals per request. There is nothing other than a conscious design decision that forces the Node code that you write to run against the same global as the code that handles the I/O guts in Node... In particular, you could have the code that listens on the socket and chunks up the byte stream into HTTP requests running against one global while all further processing of those requests runs against a different global or set of globals. It's just that Node chose not to do that. But that's not an inherent limitation of either JS the language or the V8 implementation.