Ehsan Ghanbari

Experience, DotNet, Solutions

Model classes in BackboneJS

BackbonJS is based on MV* patterns and designed for developing single page applications. It provides some basic and essential functionalities like attributes, events, and validations for models. A model of BackboneJS encapsulates model data that is further available for an application to interact with the user interface.

"Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface. With Backbone, you represent your data as Models, which can be created, validated, destroyed, and saved to the server."

As I'm only talking about BackbonJS model classes in this blog post, so take a look at a model class as an example:


var Info= Backbone.Model.extend({

   defaults: {

        'name': 'Ehsan',

        'address': {

            'street': '14st Street'

            'city': 'Tehran',

            'Phone': +9809193782914





The most important part of the above object is Backbone.Model.extend which is a backboneJS Operand. you can also create an object from the above Model:

var infoObj= new Info({

    'name': 'Ben',

    'phone' '+79***********'



by creating an object, you will get a reference to that object, and any manipulation to the object will directly manipulate the actual object in the model. For example, you can manipulate the above model  like this:


Info.set('name', 'Jim.', { validate: true });


About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
Using Generic type for type casting in F#
What's the DDD-lite?
comments powered by Disqus