I just want to fire an event when input changes the value using jQuery 1.7.2 and Backbone.js.
I currently have the following (which works)
MyView: Backbone.View.extend({
initialize: function() {
this.colorInput = $("<input />", {
"id": "color",
"name": "color",
"value": this.model.get("color")
});
var self = this;
this.colorInput.on("change", function() {
self.changeColor();
});
},
changeColor: function() {
var color = this.colorInput.val();
this.model.set("color", color);
}
});
I tried to do it in a different way when I just pass in my function.
this.colorInput.on("change", this.changeColor, this);
But when you try to do it this way, it throws an error
((jQuery.event.special [handleObj.origType] || {}). handle || handleObj.handler) .apply is not a function
.apply (matched.elem, args);
( line 3332 )
Which I canβt understand. Any ideas why this method is not working?
source
share