Yahoo! Developer Network Home - Help

YDN Site Search

# YUI Library Examples: YAHOO Global Object: Type-Checking Your Data

# YAHOO Global Object: Type-Checking Your Data

The Yahoo Global Object includes several useful type-checking methods in the `YAHOO.lang` object. Click the Check button in each row to evaluate the data.

View example in new window.

Data | isObject | isArray | isFunction
--- | --- | --- | ---
`null``` |
`[] or new Array()` |
`{} or new Object()` |
`function Foo() {}` |
`new Foo()` |
`elem.getElementsByTagName('p')` |
`YAHOO.util.Dom. getElementsByClassName( 'foo','p',elem)` |

## YAHOO.lang comes with YAHOO

`YAHOO.lang` comes bundled with the YAHOO Global Object.

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/build/yahoo/yahoo-min.js"></script> If you are using any other YUI components on your page, you should already have `YAHOO.lang` available.

## Checking types

In this example, we use a few of the type-checking methods available in `YAHOO.lang` to test various types of data.

// Test the input using YAHOO.lang type checking methods YAHOO.example.checkType = function (val) { return { 'object' : YAHOO.lang.isObject(val), 'array' : YAHOO.lang.isArray(val), 'function': YAHOO.lang.isFunction(val) }; }

## Other type checking methods

`YAHOO.lang` currently supports the following type checking methods:

- isArray
- isBoolean
- isFunction
- isNull
- isNumber
- isObject
- isString
- isUndefined
- isValue

### YAHOO Global Object Examples:

- Type-Checking Your Data
- User Agent Detection
- Creating Class Hierarchies with `YAHOO.lang.extend`
- Creating a Composition-Based Class Structure Using `YAHOO.lang.augmentProto`
- Add Behavior to Objects or Static Classes with `YAHOO.lang.augmentObject`
- Combining Simple Data Sets with `YAHOO.lang.merge`

### More YAHOO Global Object Resources:

- User's Guide (external)
- API Documentation

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings