What is evaluator function in knockout.js?

Viewed 90
1 Answers

When you define a computed observable, such as the following, notice that you are passing an anonymous function to ko.computed:

this.fullName = ko.computed(function() {
    return this.firstName() + " " + this.lastName();
}, this);

In this case the the function being passed is: function() { return this.firstName() + " " + this.lastName(); } - which is referred to as the evaluator function in the documentation.

Because Knockout uses this function to re-evaluate the value of the computed observable whenever a dependency changes.

... your evaluator function will be called once each time any of its dependencies change ...

Ref: http://knockoutjs.com/documentation/computedObservables.html

Related