Custom functions

Adding custom functions using "fn"

Occasionally, you may find opportunities to streamline your code by attaching new functionality to Knockout’s core value types. You can define custom functions on any of the following types:

Because of inheritance, if you attach a function to ko.subscribable, it will be available on all the others too. If you attach a function to ko.observable, it will be inherited by ko.observableArray but not by ko.computed.

To attach a custom function, add it to one of the following extensibility points:

  • ko.subscribable.fn
  • ko.observable.fn
  • ko.observableArray.fn
  • ko.computed.fn

Then, your custom function will become available on all values of that type created from that point onwards.

Note: It’s best to use this extensibility p