There is probably more confusion with Backbone.js Views than with other features of Backbone. In this post I’m going to describe some basic features of Backbone Views. Also, In this post we will not be rendering any HTML, but I believe the concepts that you will learn will provide the bedrock for understanding Views better.
The end goal of a Backbone View is to represents an object in the DOM. Many times a view will be created that will manipulate an object that represents an element that is not originally assigned to the DOM. At some point the view object will be assigned to the DOM element and displayed.
A view usually builds up an element and adds it to the DOM. Here’s an example of what a view represents.
Title: Happy Gilmore; Rating: PG; Year: 2008
This element would be built by the Backbone view and then added to the DOM.
It’s important to understand that once a view is added to the DOM, the view is still aware of that element in the DOM and can manage that element. So if events occur on the DOM element, such as click or keyUp, the view can be notified of these changes and take action. Also if a view references a model and the model changes, the view can be automatically updated and in-turn the DOM element will be updated to reflect the changes in the model.
“At a technical level, a Backbone view is simply a JavaScript object that manages a specific DOM element and its descendants.” http://aaronhardy.com/javascript/javascript-architecture-backbone-js-views/
“How does Backbone relate to “traditional” MVC?
Different implementations of the Model-View-Controller pattern tend to disagree about the definition of a controller. If it helps any, in Backbone, the View class can also be thought of as a kind of controller, dispatching events that originate from the UI, with the HTML template serving as the true view. We call it a View because it represents a logical chunk of UI, responsible for the contents of a single DOM element.”
http://backbonejs.org/#FAQ-mvc
I don’t want to overwhelm you with a lot of content, so I’m going to take very small step to explain some core features of Backbone views. Even though it’s our end goal, in these examples we will not assign a view to a DOM element. Everything will be logged to the browser console.

var MovieView1 = Backbone.View.extend({
//model: the Model is usually passed in through the initializer
//tagName: use default - "div"
//className: is static, dynamic or passed in through initializer - is empty by default
//el: is static, created based on tagName, or passed in through initializer
//container: this is a custom property which can be static, dynamic, or passed in through initializer
initialize: function () {
console.log("MovieView initialize");
console.log(this.model);
console.log(this.tagName);
console.log(this.className);
console.log(this.el);
console.log(this.$el);
}
});
$(function(){
var movieView1 = new MovieView1();
})
Continue reading “Re-Learning Backbone.js – View Basics”