I am using backbone validate function but it gives this error again Uncaught TypeError: Object [object Object] has no method 'apply'
. I really have no idea why is it giving me this error.
Here is my code
$(function () {
var Veh = new Backbone.Model.extend({
validate: function (attrs) {
var validColors = ['white','red', 'black'];
var colorIsValid = function (attrs) {
if(!attrs.color) return true;
return _(validColors).include(attrs.color);
}
if(!colorIsValid(attrs)) {
return 'wrong color';
}
}
});
var car = new Veh();
car.on('error', function (model, error) {
console.log(error);
});
car.set('foo', 'bar');
});