Good question. The backbone system was created to work on the server side or on the client side. jQuery was created to work in a DOM environment where a global window object must exist. In a server environment like Node, a global object is called
global .
You were close, but the actual part in the source of the baseline that sets this is actually the first two lines and the last line:
(function(){ var root = this; ... }).call(this);
Like most frameworks, Backbone runs with an anonymous function to encapsulate its configuration, but in this case it calls this method in the context of the global scope this , which allows window in the web client and global on a server like node.
Note that jQuery probably doesn't do anything like this, because it relies on dozens of DOM methods like document.getElementById . However, you can create a virtual DOM environment on the server to load jQuery. See Projects of the JSDOM Type .
Here are the conversation slides that I gave, where I cover this exact topic: https://speakerdeck.com/krunkosaurus/deep-dive-into-backbone-dot-js-internals-plus-underscore-dot-js
source share