Some of the most obvious features of Backbone.js are exposed through models, collections, and views. With its extensibility and plethora of plugins, learning Backbone.js can be used to build some amazing web applications. Especially its small and nicely annotated source code.īackbone.js provides the bare minimum required to give your web application the structure that it can benefit from. The framework may be small in size, but this is what makes it a great candidate for this thorough exploration. Although this section talks about something very obvious, when it comes to Backbone.js it is a really critical mistake to not explore the framework thoroughly. One common mistake that beginner developers often make is that they take Backbone.js to be yet another MVC-like client framework for the web. Mistake #1: Ignoring the Arsenal of Backbone.js Functionalitiesīackbone.js may be a minimalist framework, but it (along with Underscore.js) provides a plethora of features and functionalities that can easily cover the most basic and some of the critical needs that arise when developing a modern web application. In this Backbone.js tutorial, we will take a look at some common mistakes that are often made by freelance developers taking their first stab at learning Backbone.js and ways to avoid them. But they are also flexible enough to be adapted to almost any practical use. Models and collections in Backbone.js are simple, but they come with some very useful features, such as the option to easily integrate them with REST JSON APIs. Out of the box, components of Backbone.js provide an intuitive environment that you may already be familiar with when working with models and views on the back-end. We just need to finish up the render is a minimalistic framework which aims to provide a simple set of data structures and features that you can use to create a structured web application’s front-end. In Backbone, we create a new model by extending Backbone.Model like this: var Surfboard = Backbone. Our model hierarchy would look like this: Surfboard Let’s also assume that we want to keep track of the stock. That way, if a customer asks if we have a board from a particular manufacturer, or an exact model of board, or both, we can do a quick look up. Imagine we’re running a surf shop, and we want to build a database of surfboards that we carry. With that in mind, let’s draft up a little example that we’ll use going forward. Models are the heart of any JavaScript application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control. Here’s a little excerpt from the Backbone docs on models: Let’s jump into models, and gain a better understanding of them. For now though, it’s just important to understand that this logic does indeed exist, but resides inside the view. In the second part of this series, I’ll get into event handling inside the view, communicating with the model, and then sending updates back to the view. In Backbone, however, they house one other major function as I mentioned before. If you thought that it was to render data for the end user, then you’re mostly correct. What about views? Given the name “view”, it’s pretty easy to draw assumptions about their responsibility. Models can thus communicate with that database, and perform certain actions, such as CRUD operations. In a production grade application, that data is likely stored in a database somewhere. With this in mind, it’s easier to understand how a particular model is a representation of a certain set of data. Well, it’s not that complicated! I try to think of models as a “model of data”, the same way an architect might have a model of a house, or an engineer might have a model of an aerofoil. We’ve jumped the gun a bit here though, as we haven’t looked at what models and views are. To understand a bit more about the anatomy of a JavaScript MV* framework, check out this post. In MV* frameworks like Backbone, though, the controller logic is handled inside the view itself. Historically, a controller would respond to some kind of user input, and communicate that input to the model, or back to the view. Traditional MVC frameworks contain that extra C, which stands for controller. Backbone falls under the umbrella of MV* frameworks, which means that it is primarily composed of Models and Views.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |