O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending observables

Observables are a very useful and powerful part of Knockout.js. They allow you to create flexible and reliable applications. However, sometimes, you need to extend the opportunities of your observable properties. The extenders help you! As usual, let's proceed with some examples from the official documentation in detail.

Creating an extender

In this section, we will write a simple extender, as follows:

ko.extenders.logChange = function(target, option) { // 1
  target.subscribe(function(newValue) { // 2
    console.log(option + ": " + newValue); // 3
  });
  return target; // 4
};

Let's discuss it in detail:

  1. We use the ko.extenders object to create a new extender by adding a new property. In the preceding example, the property name is

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required