Introduction
Welcome to the "Demonstrating Backbone.js" article series. This article is Part 2 of the series. We will see how to create and use a Model in Backbone.js. This article starts with the concept of Backbone.js and various components of it. The previous article provided an introduction to Backbone.js and Part 1 model implementation that you can get from here.
Demonstrating Backbone.js: Implement Model Part 1
Create Model class
In order to implement Backbone.js we first need to include the Backbone.js library and since it depends upon jQuery we need to include the jQuery library to use Backbone.js.
In this following snippet at first we are creating one empty class and then we are setting the class property during object creation. Here we are setting the name and manufacturer property to a “p” object of “Product” class.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="JavaScript.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="backbone/Jquery.js"></script>
<script src="backbone/underscore-min.js"></script>
<script src="backbone/backbone-min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<script>
var Product = Backbone.Model.extend({
});
var p = new Product({ name: 'Xperia', manufacturer: 'sony' });
console.log("Name:- " + p.get('name'));
console.log("Manufacturer:- " + p.get('manufacturer'));
</script>
</form>
</body>
</html>
Here is the sample output of this example.

Set Model with various properties
In the following snippet we created a “multi” Model and in the first object of this Model we have set the “name” and “manufacturer” property and in the second model we have set a “studentname” and “college” property into it.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="JavaScript.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="backbone/Jquery.js"></script>
<script src="backbone/underscore-min.js"></script>



Join the conversation! Your thoughts help the community grow.