#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# Object Class

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

Adds utilities to the YUI instance for working with objects.

- Index
- Methods
- Properties

## Item Index

### Methods

- () static
- each static
- getValue static
- hasKey static
- hasValue static
- isEmpty static
- keys static
- owns static
- setValue static
- size static
- some static
- values static

### Properties

- _forceEnum static
- _hasEnumBug static
- _hasProtoEnumBug static

## Methods

### `()`

(

- `obj`

)
Object static

Defined in `yui/js/yui-object.js:20`

Returns a new object that uses obj as its prototype. This method wraps the native ES5 `Object.create()` method if available, but doesn't currently pass through `Object.create()`'s second argument (properties) in order to ensure compatibility with older browsers.

#### Parameters:

- `obj` Object

  Prototype object.

#### Returns:

Object: New object using obj as its prototype.

### `each`

(

- `obj`
- `fn`
- `[thisObj]`
- `[proto=false]`

)
YUI static chainable

Defined in `yui/js/yui-object.js:237`

Executes a function on each enumerable property in obj. The function receives the value, the key, and the object itself as parameters (in that order).

By default, only properties owned by obj are enumerated. To include prototype properties, set the proto parameter to `true`.

#### Parameters:

- `obj` Object

  Object to enumerate.

- `fn` Function

  Function to execute on each enumerable property.

  - `value` Mixed

    Value of the current property.

  - `key` String

    Key of the current property.

  - `obj` Object

    Object being enumerated.

- `[thisObj]` Object optional

  `this` object to use when calling fn.

- `[proto=false]` Boolean optional

  Include prototype properties.

#### Returns:

YUI: the YUI instance.

### `getValue`

(

- `o`
- `path`

)
Any static

Defined in `yui/js/yui-object.js:303`

Retrieves the sub value at the provided path, from the value object provided.

#### Parameters:

- `o` Object

  The object from which to extract the property value.

- `path` Array

  A path array, specifying the object traversal path from which to obtain the sub value.

#### Returns:

Any: The value stored in the path, undefined if not found, undefined if the source is not an object. Returns the source object if an empty path is provided.

### `hasKey`

(

- `obj`
- `key`

)
Boolean static

Defined in `yui/js/yui-object.js:110`

Alias for `owns()`.

#### Parameters:

- `obj` Object

  Object to test.

- `key` String

  Property name to look for.

#### Returns:

Boolean: `true` if key exists on obj, `false` otherwise.

### `hasValue`

(

- `obj`
- `value`

)
Boolean static

Defined in `yui/js/yui-object.js:223`

Returns `true` if the object owns an enumerable property with the specified value.

#### Parameters:

- `obj` Object

  An object.

- `value` Any

  The value to search for.

#### Returns:

Boolean: `true` if obj contains value, `false` otherwise.

### `isEmpty`

(

- `obj`

)
Boolean static

Defined in `yui/js/yui-object.js:367`

Available since 3.2.0

Returns `true` if the object has no enumerable properties of its own.

#### Parameters:

- `obj` Object

  An object.

#### Returns:

Boolean: `true` if the object is empty.

### `keys`

(

- `obj`

)
String[] static

Defined in `yui/js/yui-object.js:121`

Returns an array containing the object's enumerable keys. Does not include prototype keys or non-enumerable keys.

Note that keys are returned in enumeration order (that is, in the same order that they would be enumerated by a `for-in` loop), which may not be the same as the order in which they were defined.

This method is an alias for the native ES5 `Object.keys()` method if available.

#### Parameters:

- `obj` Object

  An object.

#### Returns:

String[]: Array of keys.

#### Example:

    Y.Object.keys({a: 'foo', b: 'bar', c: 'baz'});
    // => ['a', 'b', 'c']

### `owns`

(

- `obj`
- `key`

)
Boolean static

Defined in `yui/js/yui-object.js:95`

Returns `true` if key exists on obj, `false` if key doesn't exist or exists only on obj's prototype. This is essentially a safer version of `obj.hasOwnProperty()`.

#### Parameters:

- `obj` Object

  Object to test.

- `key` String

  Property name to look for.

#### Returns:

Boolean: `true` if key exists on obj, `false` otherwise.

### `setValue`

(

- `o`
- `path`
- `val`

)
Object static

Defined in `yui/js/yui-object.js:332`

Sets the sub-attribute value at the provided path on the value object. Returns the modified value object, or undefined if the path is invalid.

#### Parameters:

- `o` Object

  The object on which to set the sub value.

- `path` Array

  A path array, specifying the object traversal path at which to set the sub value.

- `val` Any

  The new value for the sub-attribute.

#### Returns:

Object: The modified object, with the new sub value set, or undefined, if the path was invalid.

### `size`

(

- `obj`

)
Number static

Defined in `yui/js/yui-object.js:207`

Returns the number of enumerable keys owned by an object.

#### Parameters:

- `obj` Object

  An object.

#### Returns:

Number: The object's size.

### `some`

(

- `obj`
- `fn`
- `[thisObj]`
- `[proto=false]`

)
Boolean static

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

Executes a function on each enumerable property in obj, but halts if the function returns a truthy value. The function receives the value, the key, and the object itself as paramters (in that order).

By default, only properties owned by obj are enumerated. To include prototype properties, set the proto parameter to `true`.

#### Parameters:

- `obj` Object

  Object to enumerate.

- `fn` Function

  Function to execute on each enumerable property.

  - `value` Mixed

    Value of the current property.

  - `key` String

    Key of the current property.

  - `obj` Object

    Object being enumerated.

- `[thisObj]` Object optional

  `this` object to use when calling fn.

- `[proto=false]` Boolean optional

  Include prototype properties.

#### Returns:

Boolean: `true` if any execution of fn returns a truthy value, `false` otherwise.

### `values`

(

- `obj`

)
Array static

Defined in `yui/js/yui-object.js:177`

Returns an array containing the values of the object's enumerable keys.

Note that values are returned in enumeration order (that is, in the same order that they would be enumerated by a `for-in` loop), which may not be the same as the order in which they were defined.

#### Parameters:

- `obj` Object

  An object.

#### Returns:

Array: Array of values.

#### Example:

    Y.Object.values({a: 'foo', b: 'bar', c: 'baz'});
    // => ['foo', 'bar', 'baz']

## Properties

### `_forceEnum`

String[] protected static

Defined in `yui/js/yui-object.js:49`

Property names that IE doesn't enumerate in for..in loops, even when they should be enumerable. When `_hasEnumBug` is `true`, it's necessary to manually enumerate these properties.

### `_hasEnumBug`

Boolean protected static

Defined in `yui/js/yui-object.js:68`

`true` if this browser has the JScript enumeration bug that prevents enumeration of the properties named in the `_forceEnum` array, `false` otherwise.

See: - https://developer.mozilla.org/en/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug - http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation

### `_hasProtoEnumBug`

Boolean protected static

Defined in `yui/js/yui-object.js:84`

`true` if this browser incorrectly considers the `prototype` property of functions to be enumerable. Currently known to affect Opera 11.50.