API Docs for: 1.0.0
Show:

Object~extras Class

Augments Y.Object with the same higher-order functions that array-extras adds to Y.Array. Note that, unlike Y.Array, iteration order for objects is arbitrary, so be careful when applying non-commutative operations!

Item Index

Methods

Methods

evalGet

(
  • o
  • s
)
Mixed static

Extracts a value from an object, given a string containing a valid JavaScript expression. In a browser, this uses eval(). In Adobe AIR, it parses the string, thereby restricting the syntax to only dot notation.

Parameters:

  • o Object

    the object from which to extract a value

  • s String

    the expression

Returns:

Mixed:

requested value

evalSet

(
  • o
  • s
  • v
)
static

Sets a value inside an object, given a string containing a valid JavaScript expression. In a browser, this uses eval(). In Adobe AIR, it parses the string, thereby restricting the syntax to only dot notation.

Parameters:

  • o Object

    the object in which to set a value

  • s String

    the expression

  • v Mixed

    the value to set

every

(
  • o
  • f
  • c
  • proto
)
Boolean static

Executes the supplied function on each item in the object. Iteration stops if the supplied function does not return a truthy value. 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:

  • o Object

    the object to iterate

  • f Function

    the function to execute on each item

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Boolean:

true if every item in the array returns true from the supplied function, false otherwise

filter

(
  • o
  • f
  • c
  • proto
)
Object static

Executes the supplied function on each item in the object. Returns a new object containing the items for which the supplied function returned a truthy value. 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:

  • o Object

    the object to iterate

  • f Function

    the function to execute on each item

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Object:

object of items for which the supplied function returned a truthy value (empty if it never returned a truthy value)

find

(
  • o
  • f
  • c
  • proto
)
Mixed static

Executes the supplied function on each item in the object, searching for the first item that matches the supplied function. 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:

  • o Object

    the object to iterate

  • f Function

    the function to execute on each item

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Mixed:

the first item for which the supplied function returns true, or null if it never returns true

invoke

(
  • o
  • f
  • args
)
Object static

Executes a named method on each item in the object. Items that do not have a function by that name will be skipped.

Parameters:

  • o Object

    the object to iterate

  • f String

    the function to invoke

  • args Any multiple

    any number of additional args are passed as parameters to the execution of the named method

Returns:

Object:

all return values, mapped according to the item key

keyOf

(
  • o
  • v
  • proto
)
String static

Executes the supplied function on each item in the object, searching for the first item that matches the supplied function.

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

Parameters:

  • o Object

    the object to iterate

  • v Mixed

    the value to search for

  • proto Boolean

    include prototype properties

Returns:

String:

key of an item strictly equal to v, or null if not found

map

(
  • o
  • f
  • c
  • proto
)
Object static

Executes the supplied function on each item in the object and returns a new object with the results. 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:

  • o Object

    the object to iterate

  • f String

    the function to invoke

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Object:

all return values, mapped according to the item key

partition

(
  • o
  • f
  • c
  • proto
)
Object static

Partitions an object into two new objects, one with the items for which the supplied function returns true, and one with the items for which the function returns false. 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:

  • o Object

    the object to iterate

  • f Function

    the function to execute on each item

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Object:

object with two properties: matches and rejects. Each is an object containing the items that were selected or rejected by the test function (or an empty object if none).

reduce

(
  • o
  • init
  • f
  • c
  • proto
)
Mixed static

Executes the supplied function on each item in the object, folding the object into a single value. The function receives the value returned by the previous iteration (or the initial value if this is the first iteration), the value being iterated, the key, and the object itself as parameters (in that order). The function must return the updated value.

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

Parameters:

  • o Object

    the object to iterate

  • init Mixed

    the initial value

  • f String

    the function to invoke

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Mixed:

final result from iteratively applying the given function to each item in the object

reduceRight

(
  • o
  • init
  • f
  • c
  • proto
)
Mixed static

Executes the supplied function on each item in the object, starting at the end and folding the object into a single value. The function receives the value returned by the previous iteration (or the initial value if this is the first iteration), the value being iterated, the key, and the object itself as parameters (in that order). The function must return the updated value.

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

Since the order of iteration is undefined for objects, this is identical to reduce.

Parameters:

  • o Object

    the object to iterate

  • init Mixed

    the initial value

  • f String

    the function to invoke

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Mixed:

final result from iteratively applying the given function to each item in the object

reject

(
  • o
  • f
  • c
  • proto
)
Object static

Executes the supplied function on each item in the object. Returns a new object containing the items for which the supplied function returned a falsey value. 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:

  • o Object

    the object to iterate

  • f Function

    the function to execute on each item

  • c Object

    optional context object

  • proto Boolean

    include prototype properties

Returns:

Object:

object of items for which the supplied function returned a falsey value (empty if it never returned a falsey value)

zip

(
  • a1
  • a2
)
Object static

Creates an object by pairing the corresponding elements of two arrays.

Parameters:

  • a1 Array

    the keys which must be strings

  • a2 Array

    the values

Returns:

Object:

object formed by pairing each element of the first array with an item in the second array having the corresponding index