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

The ko.utils reference


The ko.utils namespace is Knockout's bucket for utility functions. Not all of these functions are publicly exposed—at least not in a usable way. Knockout's minification process obfuscates more than half of them. As the unobfuscated methods are a public API that Knockout has committed to providing, changing them would be a major change. Despite considering all of the exposed methods on the ko.utils part of the API, Knockout does not provide any documentation for them.

Here is a complete list of the public functions on ko.utils as of Knockout 3.2:

  • addOrRemoveItem(array, item, included): If included is true, it will add the item to the array if it is not already there; if included is false, it will remove the item from the array if it is present.

  • arrayFilter(array, predicate): This returns an array of elements from the array that returns true from the predicate using predicate(element, index).

  • arrayFirst(array, predicate, predicateOwner): This returns the first element...