This is in a BackBone Model:
calculatePrice() {
}
initialize() {
_.bindAll(this, 'caclulatePrice');
this.on("change", function() {
this.calculatePrice();
});
}
The problem is when this compiles the inner this is just this and not the _this which is actually the model.
Having looked around (and based on similar cases in CoffeeScript) it looks like the answer is something to do with => But I can't make this work e.g
this.on("change", function() => {
doesn't compile.
What do I need to do to make the inner this refer to the BackBone model (the class it is in)?
Update:
This works but it can't be the 'right' way.
let that = this;
this.on("change", function() { that.caclulatePrice() });