Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is evaluator function in knockout.js?

Tags:

knockout.js

I was reading knockout.js docs and got to read many times of the term "evaluator" a lot , like in here

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

and

http://knockoutjs.com/documentation/computed-dependency-tracking.html

Can somebody please explain what an evaluator function is ?

like image 526
Chirag Avatar asked May 07 '26 05:05

Chirag


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

like image 93
Nisarg Shah Avatar answered May 10 '26 18:05

Nisarg Shah