From the course: Learning Backbone.js

Understanding Backbone and other Model-View-Controller (MVC) libraries - Backbone.js Tutorial

From the course: Learning Backbone.js

Start my 1-month free trial

Understanding Backbone and other Model-View-Controller (MVC) libraries

MVC is playing a huge role in JavaScript development at the time of this recording. As a result, many, many JavaScript MVC libraries and frameworks have been released besides Backbone. In this video, I want to have a quick discussion about the MVC landscape in JavaScript, focusing on Backbones benefits. MVC has a long history of solving programming problems. Programmers writing in something like Java or C consistently use MVC to structure their code. It's not the solution to all of their problems, but it is a solution to most of them. JavaScript developers have embraced MVC because of this, particularly when building single page applications, which are commonly referred to as SPAs. SPAs are websites where all interaction is contained on to one webpage, and not multiple webpages. Any information that you send or receive, will be contained on one page, without that page needing to be refreshed. This has led to an arrival of quite a few JavaScript MVC libraries and frameworks. Some of the earliest frameworks being Spine, SproutCore, and the sensibly named, JavaScript MVC. Now again, these things just mentioned, are JavaScript MVC frameworks. Backbone is a JavaScript MVC library and that's a key difference. In the JavaScript MVC context, a framework usually means that you need to configure your code to get things done. Maybe you need to add some code to your HTML page, or give a page element a certain ID class name. But to get the framework to do its job properly, you need to configure things. A library in the JavaScript in the MVC context usually means that your library code has some pre-built functions that you can use to manipulate page content. You don't need to configure anything on your web page. You just reference a library's pre-built code in your JavaScript to get specific tasks done on your web page. This is quite similar to how jQuery works. Backbone is not the only JavaScript library. There are others, with Knockout being another popular one. And there are also other popular frameworks, with Angular and Ember being the most popular. Now at the time of this recording, Backbone, Knockout, Angular and Ember are definitely the most popular JavaScript libraries in frameworks, as far as JavaScript MVC goes. They have large communities behind them, books written about them, and lots of plugins written for them. I'll be completely honest and say that the frameworks can be easier to use than the libraries and I want you to take a look at them when you can. But, as this is a Backbone course, I'm going to point out the benefits that Backbone has when compared to these other options. Because it's a library instead of a framework, the biggest advantage that Backbone has over the others is that it's highly customizable. Frameworks usually require you do things their way if you want to use them within your site of web app. You have to configure their code pretty much exactly as they tell you to, leaving little room for flexibility. Backbone doesn't do that. You really just need to utilize the components and their pre-defined properties and methods. But that's really it. This leaves you with a lot of room for flexibility. In this case we say that Backbone is unopinionated. Backbone is also one of the most lightweight, among all the frameworks and libraries. When the code is reduced to its smallest usable form, it's file size is just over six kilobytes. Meaning that it will load onto your webpage very quickly. Backbone also has one of the most extensive communities built around it. A web search will turn up multiple articles, documentation and plugins that focus specifically on Backbone. Now, I need to be fair and say that other frameworks are catching up to Backbone, Angular in particular. But while Backbone wasn't the first, it was one of the first to become popular. It's because of this, that the Backbone community is a more extensive, in terms of community help, user groups and having a wide array of plugins available to it.

Contents