How do I add a custom method to a backbone model?
backbone.js, marionette
Solution
Any reason not to do the obvious?
Model = Backbone.Model.extend({
func: function() {
},
})
Problem
I've tried: ``` initialize: function() { if (this.get("id") == "modelOfInterest") { var func = function() { //do some stuff with the model } _.bind(func, this) } } ``` and ``` initialize: function() { if (this.get("id") == "modelOfInterest") { var func = function() { //do some stuff with the model } this.on("func", func, this); } } ``` However in both cases: ``` myModelInstance.func(); //object has no method func ``` I'd prefer not to use `_.bindAll()`. I've edited the code above to show that I am trying to bind func to only one model. The model is initialize when it is added to a collection : all the models fire initialize at the same time and I just want to bind func to one of them.