I am learning backbone. I am trying to use on event for change. But it gives me this error Uncaught TypeError: Object function (){ parent.apply(this, arguments); } has no method 'on' on line 6. Below is my code
$(function () {
var ford = new Backbone.Model.extend({
type: 'car',
color: 'blue'
});
ford.on('change', function () {
console.log('something changed');
});
ford.set('type', 'truck');
});
How can I make this work?
You haven’t created an instance of ford yet. Do something like
and then have another function listen to its ‘change‘ event.
Here, extend is used to create a constructor function. You have to create objects to bring the model to life.