Knockout provides a way to add additional reusable functionality to the observables through the use of extenders. Knockout extenders could be used to add additional properties to the observable or to intercept and rewrite its value. Extenders could also be used to validate the model. This section will explore and demonstrate the use of extenders for validating the model. The example in this section will apply this method of validation only to the first name field.
An extender is created by adding a method to the ko.extenders
object. The method takes two parameters: the observable and an option value. The option value is specified when the observable is extended. The method should return an observable. This can either be the observable itself or a computed observable that manipulates the value of the original observable.
Let's create an extender that will extend the firstName
observable in our registration form application and mark it as required...