What the heck are backbone objects anyways... when I pass the view a model object, where is that model persisted on the page?

Sorry if I'm misunderstanding you, but I think you have a misunderstanding of what's happening in the browser. The javascript engine runs entirely separately from the DOM. All of Backbone (Models, Collections, Views, Router) are stored as variables, referenced,constructed and invoked separately from the DOM. Javascript can modify the DOM (and can bind or be bound to DOM actions), but it's all happening somewhat at arms length. This is why Node.js can run JavaScript code, but not be a browser. It's a little confusing cause you reference scripts within the DOM to load or invoke them, but other than that, entirely separate things.

In learning Backbone (or Angular, Ember, etc), you're using a series of tools to make this separation of "code that does computing" and "code that specifically modifies the UI" (but still JavaScript code) a lot easier. In Backbone, the View is a JavaScript object that helps abstract (structure and simplify) the process of modifying the UI, but it's all happening in JavaScript land, not the DOM. (This is a little bit of a simplification because of how a Backbone.View's view hash works to listen to the DOM, but all other Backbone event listening and triggering is done in JavaScript not the DOM)

So as to your question of "where does it live?", the answer is basically the same place as where all the other JavaScript code lives (like the jQuery $, or the Backbone.Model constructor you use): in memory, in the scope of the variables you define and the references you store. Technically, it's being placed on the memory heap, and removed when nothing references it. So when you make a new model and inject it into a view, a reference to that model (view.model) is being created, which allows you to access the model. If you delete the view, the model will go away because nothing references it. If you had added the model to a collection, that collection will have a reference and it won't be deleted (as long as something references it, and that something has a reference, etc. it will exist).

Sorry if this response seems pedantic or patronizing and you know all this. I'm just trying to understand the context of your question. I had to learn all this at one time too :-)

/r/backbonejs Thread Parent