#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# Lang Class

Defined in: `yui/js/yui-lang.js:9`
Module: yui-base
Parent Module: yui

Provides core language utilites and extensions used throughout YUI.

- Index
- Methods

## Item Index

### Methods

- _isNative static
- isArray static
- isBoolean static
- isDate static
- isFunction static
- isNull static
- isNumber static
- isObject static
- isString static
- isUndefined static
- isValue static
- now static
- sub static
- trim static
- trimLeft static
- trimRight static
- type static

## Methods

### `_isNative`

(

- `fn`

)
Boolean protected static

Defined in `yui/js/yui-lang.js:39`

Available since 3.5.0

Returns `true` if the given function appears to be implemented in native code, `false` otherwise. Will always return `false` -- even in ES5-capable browsers -- if the `useNativeES5` YUI config option is set to `false`.

This isn't guaranteed to be 100% accurate and won't work for anything other than functions, but it can be useful for determining whether a function like `Array.prototype.forEach` is native or a JS shim provided by another library.

There's a great article by @kangax discussing certain flaws with this technique: http://perfectionkills.com/detecting-built-in-host-methods/

While his points are valid, it's still possible to benefit from this function as long as it's used carefully and sparingly, and in such a way that false negatives have minimal consequences. It's used internally to avoid using potentially broken non-native ES5 shims that have been added to the page by other libraries.

#### Parameters:

- `fn` Function

  Function to test.

#### Returns:

Boolean: `true` if fn appears to be native, `false` otherwise.

### `isArray`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:70`

Determines whether or not the provided item is an array.

Returns `false` for array-like collections such as the function `arguments` collection or `HTMLElement` collections. Use `Y.Array.test()` if you want to test for an array-like collection.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is an array.

### `isBoolean`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:86`

Determines whether or not the provided item is a boolean.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is a boolean.

### `isDate`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:97`

Determines whether or not the supplied item is a date instance.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is a date.

### `isFunction`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:108`

Determines whether or not the provided item is a function. Note: Internet Explorer thinks certain functions are objects:

    var obj = document.createElement("object");
    Y.Lang.isFunction(obj.getAttribute) // reports false in IE

    var input = document.createElement("input"); // append to body
    Y.Lang.isFunction(input.focus) // reports false in IE

You will have to implement additional tests if these functions matter to you.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is a function.

### `isNull`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:136`

Determines whether or not the provided item is null.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is null.

### `isNumber`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:147`

Determines whether or not the provided item is a legal number.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is a number.

### `isObject`

(

- `o`
- `failfn`

)
Boolean static

Defined in `yui/js/yui-lang.js:158`

Determines whether or not the provided item is of type object or function. Note that arrays are also objects, so `Y.Lang.isObject([]) === true`.

#### Parameters:

- `o` Object

  The object to test.

- `failfn` Boolean

  fail if the input is a function.

#### Returns:

Boolean: true if o is an object.

### `isString`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:175`

Determines whether or not the provided item is a string.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is a string.

### `isUndefined`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:186`

Determines whether or not the provided item is undefined.

#### Parameters:

- `o` Object

  The object to test.

#### Returns:

Boolean: true if o is undefined.

### `isValue`

(

- `o`

)
Boolean static

Defined in `yui/js/yui-lang.js:197`

A convenience method for detecting a legitimate non-null value. Returns false for null/undefined/NaN, true for other values, including 0/false/''

#### Parameters:

- `o` Object

  The item to test.

#### Returns:

Boolean: true if it is not null/undefined/NaN || false.

### `now`

() Number static

Defined in `yui/js/yui-lang.js:222`

Available since 3.3.0

Returns the current time in milliseconds.

#### Returns:

Number: Current time in milliseconds.

### `sub`

(

- `s`
- `o`

)
String static

Defined in `yui/js/yui-lang.js:234`

Available since 3.2.0

Lightweight version of `Y.substitute`. Uses the same template structure as `Y.substitute`, but doesn't support recursion, auto-object coersion, or formats.

#### Parameters:

- `s` String

  String to be modified.

- `o` Object

  Object containing replacement values.

#### Returns:

String: the substitute result.

### `trim`

(

- `s`

)
String static

Defined in `yui/js/yui-lang.js:251`

Returns a string without any leading or trailing whitespace. If the input is not a string, the input will be returned untouched.

#### Parameters:

- `s` String

  the string to trim.

#### Returns:

String: the trimmed string.

### `trimLeft`

(

- `s`

)
String static

Defined in `yui/js/yui-lang.js:269`

Returns a string without any leading whitespace.

#### Parameters:

- `s` String

  the string to trim.

#### Returns:

String: the trimmed string.

### `trimRight`

(

- `s`

)
String static

Defined in `yui/js/yui-lang.js:282`

Returns a string without any trailing whitespace.

#### Parameters:

- `s` String

  the string to trim.

#### Returns:

String: the trimmed string.

### `type`

(

- `o`

)
String static

Defined in `yui/js/yui-lang.js:295`

Returns one of the following strings, representing the type of the item passed in:

- "array"
- "boolean"
- "date"
- "error"
- "function"
- "null"
- "number"
- "object"
- "regexp"
- "string"
- "undefined"

Known issues:

- `typeof HTMLElementCollection` returns function in Safari, but `Y.Lang.type()` reports "object", which could be a good thing -- but it actually caused the logic in `Y.Lang.isObject` to fail.

#### Parameters:

- `o` Object

  the item to test.

#### Returns:

String: the detected type.