Home > backbone.js, javascript > backbone.js learning note [1]

backbone.js learning note [1]

Keep track of state change example:

    Stock = Backbone.Model.extend({
        defaults: {
            price: null,
        },
        initialize: function(){
            this.bind('change:price', function() {
                var px=this.get('price');
                console.log('price changed to: '+px);
            });
        },
        price_change: function(newprice) {
            this.set({price:newprice});
        }
    });

    var stock=new Stock({price:1234.55});
    stock.price_change(456);
    // the console output from the last line:
    // price changed to: 456

References:
http://backbonetutorials.com/what-is-a-model/

Advertisements
Categories: backbone.js, javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: