backbone MODEL

model

by bhupendra negi

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>

JavaScript

var Human = Backbone.Model.extend({

    initialize: function () {
        alert("welcome to backbone");
        this.on("change:company", function (model) {
            var newname = model.get("company");
            alert("changed company to =>" + newname);
        });


    },
    defaults: {
        building: "RF"
    },
    change: function (newcompany) {
        this.set({
            company: newcompany
        })
    }

});

//intialze with attributes
// these attributes in previous field
var human = new Human({
    name: "rock",
    year: 2015,
    company: "3DPLM"
});

// add more attributes in changed filed
//human.set( {company:"3DPLM"});

//all attributes in all field

// call custom function

human.change("infy");

//GET attributes
//human.get("name");

console.log(human);