I have been going thru this book “developing backbone.js application”
where on page 18 theres a model function which goes like this:
(function($){
var Photo = Backbone.Model.extend({
defaults: {
'src': 'placeholder.jpg',
'title':'an image placeholder',
'coordinates':[0,0]
},
initialize:function(){
this.on("change:sr", function(){
var src = this.get("src");
console.log("Image src has been updated to: "+src);
});
},
changeSrc: function(source){
this.set({'src':source});
}
});
var somePhoto = new Photo({'src':'test.jpg', 'title':'testing'});
somPhoto.changeSrc('thatPhoto.jpg');
})(jQuery);
Its give me an error as
TypeError: this.on is not a function
this.on("change:src", function(){
on console.
Any Idea how i may solve this problem. I’m entirely new to Backbone.js.
Any Help is appreciated.
You might be using an old version of Backbone.
on/offwere only added on 0.9.0, before that they were calledbindandunbind.You should update to the latest Backbone (0.9.9 at the time of writing).