Adds utilities to the YUI instance for working with objects.
()obj
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.
obj
Object
Prototype object.
New object using obj as its prototype.
eachobj
fn
[thisObj]
[proto=false]
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.
the YUI instance.
getValueo
path
Retrieves the sub value at the provided path, from the value object provided.
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.
hasKeyobj
key
Alias for owns().
true if key exists on obj, false otherwise.
hasValueobj
value
Returns true if the object owns an enumerable property with the specified
value.
obj
Object
An object.
value
Any
The value to search for.
true if obj contains value, false otherwise.
isEmptyobj
Returns true if the object has no enumerable properties of its own.
obj
Object
An object.
true if the object is empty.
keysobj
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 and non-buggy. The Opera 11.50 and Android 2.3.x versions of
Object.keys() have an inconsistency as they consider prototype to be
enumerable, so a non-native shim is used to rectify the difference.
obj
Object
An object.
Array of keys.
Y.Object.keys({a: 'foo', b: 'bar', c: 'baz'});
// => ['a', 'b', 'c']
ownsobj
key
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().
true if key exists on obj, false otherwise.
setValueo
path
val
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.
The modified object, with the new sub value set, or undefined, if the path was invalid.
sizeobj
Returns the number of enumerable keys owned by an object.
obj
Object
An object.
The object's size.
someobj
fn
[thisObj]
[proto=false]
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.
true if any execution of fn returns a truthy value,
false otherwise.
valuesobj
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.
obj
Object
An object.
Array of values.
Y.Object.values({a: 'foo', b: 'bar', c: 'baz'});
// => ['foo', 'bar', 'baz']
_forceEnumProperty 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.
_hasEnumBugtrue if this browser has the JScript enumeration bug that prevents
enumeration of the properties named in the _forceEnum array, false
otherwise.
See:
_hasProtoEnumBugtrue if this browser incorrectly considers the prototype property of
functions to be enumerable. Currently known to affect Opera 11.50 and Android 2.3.x.