Chapter 9. Utilities

Compared to other programming languages, JavaScript has historically included only a very small number of core utility methods. For years, if you wanted to trim whitespace from a string or enumerate an object’s keys, you had to implement that functionality yourself.

Recently, JavaScript has been evolving to fill in some of these feature gaps. Newer JavaScript engines still provide very minimal core APIs, but the environment at least is starting to look a little more like what developers coming over from other languages might expect.

As a comprehensive JavaScript framework, YUI provides a large number of utility methods. Some YUI utility methods mirror a native ECMAScript method, enabling you to use native code when that is available, but falling back to YUI code in older browsers. Other YUI utility methods provide a nicer or more powerful wrapper around a lower-level native API. Finally, some YUI utility methods provide high-level features or solve common problems that aren’t yet addressed by W3C or ECMAScript specifications.

This chapter provides a brief survey of some key YUI utilities, including language helpers (type checking, array and object manipulation) data converters, and formatters, application development (browser history), and form utilities (validation, keyboard and input change events).

As always, be sure to consult the YUI documentation in order to fully understand the API. Many recipes in this chapter show off only a small subset of what a particular ...

Get YUI 3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.