I have a class in CS:
class Model
constructor: (objectParams) ->
@object = ##object
###constructor
baseObject: => {}
validate: ko.computed =>
console.log ko.toJS @object
The problem is with ‘validate’ it is a prototype property where the binding context of the ko.computed function should be the constructor but instead gets compiled to this:
Model.prototype.validate = ko.computed(function() {
return console.log(ko.toJS(Model.object));
});
I want it to be binded to the constructor but the fat arrow => seems to be working only this way:
property: () =>
and this way it won’t work
validate: =>
ko.computed => console.log ko.toJS @object
because ko.computed can’t be defined inside a function
how can i solve?
Binding your function to the instance and “preprocessing” it works like this
from your pipe function (in your case ko.computed) return another function that wraps your initial function and calls it via .apply.
No need for the fat arrow as your are calling apply with @