This entry is part 2 of 14 in the series for A Complete Guide for Learning Backbone Js
- Introduction and Installation
- Defining Models in backbone js
- Adding Validations in models backbone js
- Explaining views in backbone js
- How to use templates in backbone js
- How to improve templates in backbone js
- Collections in backbone js
- Collection views in backbone js
- Template helpers in backbone js
- How to use namespace in backbone js
- How to handle dom events in backbone js and define your custom events (Live Demo)
- Routing in backbone js
In this topic we will not be discussing backbone, We will be learning how to represent data. We are using the same application that we build in previous blog post and building on top of it. Let’s create a new file, i.e., main.js and let’s include that in
Defining the object
Now let’s define an object Person which has some attributes like name, age or occupation. Here is the code for that.
So why we are defining in this way is evident because we want to give structure. Classes and objects are the best way to describe a structure. So in the code sample above, we defined a class Person and a function work. Save the file and open
index.html file on browser. (Make sure you have included main.js file in
Fire up the console and fire these commands
So from Chrome developer console, you can trigger following things to see some results.
Cool. Let’s take a look at the screenshot explaining things on chrome console.
Output on Chrome Console
If you are facing any issues. Check out the source code files at github. I will be creating more and more directories in the same repo regarding each post. Still, if you have any doubts you can comment on the blog post itself, and I will try to reply back asap.