When using knockout, what is the advantage of using calculated observable data rather than simple functions?
Take the following viewmodel constructor and html snippet, for example:
var ViewModel = function(){ var self = this; self.someProperty = ko.observable("abc"); self.anotherProperty = ko.observable("xyz"); self.someComputedProperty = function(){ return self.someProperty() + self.anotherProperty(); }; }; <input data-bind="value: someProperty"/> <input data-bind="value: anotherProperty"/> <p data-bind="text: someComputedProperty()"></p>
Everything here seems to work the way you expected, so there is a reason I should use:
โvar ViewModel = function(){ var self = this; self.someProperty = ko.observable("abc"); self.anotherProperty = ko.observable("xyz"); self.someComputedProperty = ko.computed(function(){ return self.someProperty() + self.anotherProperty(); }); }; <input data-bind="value: someProperty"/> <input data-bind="value: anotherProperty"/> <p data-bind="text: someComputedProperty"></p>
I noticed that the documentation at http://knockoutjs.com/documentation/computedObservables.html states that "... declarative bindings are just implemented as computed observables", what do I need to use them explicitly in my models?
Duncan Jul 17 2018-12-17T00: 00Z
source share