Custom functions

Knockout.js allows you to write your own custom functions to extend the capabilities of a standard Knockout.js object. The following objects from the Knockout.js hierarchy can be extended:

  • ko.subscribable (root object)
  • ko.computed (inherited from ko.subscribable)
  • ko.observable (inherited from ko.subscribable)
  • ko.observableArray (inherited from ko.observable)

If you write a custom function for an object, the inheritors of the object will also have the written function. For example, you can use a custom function of ko.observable with ko.observableArray.

An example with array filtering

Let's learn how to write a custom function with the following example. We will write the filterByProperty function for ko.observableArray. This function ...

Get Getting Started with Knockout.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.