Book Image

Mastering KnockoutJS

By : Timothy Moran
Book Image

Mastering KnockoutJS

By: Timothy Moran

Overview of this book

Table of Contents (16 chapters)
Mastering KnockoutJS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Binding the handler preprocessing


So far, we have looked at two properties of binding handlers: the init and update functions. Binding handlers have another optional function, which is preprocess, that is run before the init function. A preprocessor's purpose is to modify the data-binding attribute before Knockout determines what bindings are to be applied.

Preprocessors don't deal with elements or binding contexts; they just deal with the strings that the binding will evaluate. For example, if we had a preprocessor that converts all text bindings to uppercase, then the following span element will be processed:

<span data-bind="text: 'That Guy'"></span>

This span element would be processed as if it was written like this:

<span data-bind="text: 'That Guy'.toUpperCase()"></span>

If you were to inspect the HTML after this, you will still see the original data-bind attribute. This is because preprocessors don't actually deal with elements; they just modify the binding strings...