YUI~funcprog Class
Augments global Y object with the same higher-order functions that array-extras adds to Y.Array. Note that, unlike arrays and NodeLists, iteration order for an object is arbitrary, so be careful when applying non-commutative operations!
Item Index
Methods
every
-
o
-
f
-
c
-
proto
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
true if every item in the array returns true from the supplied function, false otherwise
filter
-
o
-
f
-
c
-
proto
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
array or 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
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
the first item for which the supplied function returns true, or null if it never returns true
map
-
o
-
f
-
c
-
proto
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Stringthe function to invoke
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
array or object of all return values, mapped according to the item key
partition
-
o
-
f
-
c
-
proto
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
object with two properties: matches and rejects. Each is an array or 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
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.
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
init
Mixedthe initial value
-
f
Stringthe function to invoke
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
final result from iteratively applying the given function to each item in the object
reduceRight
-
o
-
init
-
f
-
c
-
proto
Executes the supplied function on each item in the object, starting from 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.
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
init
Mixedthe initial value
-
f
Stringthe function to invoke
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
final result from iteratively applying the given function to each item in the object
reject
-
o
-
f
-
c
-
proto
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).
Supports arrays, objects, and NodeLists.
Parameters:
-
o
Mixedthe object to iterate
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
-
proto
Booleanif true, prototype properties are iterated on objects
Returns:
array or object of items for which the supplied function returned a falsey value (empty if it never returned a falsey value)