backbone.js Sync Basic Example


The sync() method reads and fetched the model data

     Backbone.sync = function(method, model) {
        document.write("The state of the model is:");

        //The 'method' specifies state of the model
        document.write(method + ": " + JSON.stringify(model));

     //'myval' is a collection instance and contains the values which are to be fetched in the collection
     var myval = new Backbone.Collection({
        title:"Farhad Mehryari Official Website"

     //The myval.fetch() method displays the model's state by delegating to sync() method

this code will outputs :

The state of the model is:
read: [{"site":"","title":"Farhad Mehryari Official Website"}]