Open kohenkatz opened 8 years ago
Thinking about it, probably the easiest way to do this is to add a check here for "if this is a function that takes no arguments"
Sorry. It looks like when using ko.track
that functions aren't converted to ko.computed
, but to a regular ko.observable
.
I made the change and added a test for it in https://github.com/kohenkatz/knockout-es5/tree/patch-1
Should I make a Pull Request for it?
According to http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-plugin-to-simplify-your-syntax/, functions are supposed to be left alone, but since they aren't, this change seems like a good one. I'm not a maintainer here, but just commenting.
As described in the original blog post, functions in an object that is
ko.track
ed will be wrapped in observables as well and can be used as if they werecomputed
. However, unlike computed observables, these "implicit"computed
s can be overwritten very easily (possibly accidentally, ossibly maliciously).I have created a simple example to illustrate this problem.
Paste the following code in the console:
I would suggest that, by default, these observables created from functions should have only getters, not setters.