NodeList~extras2 Class
Augments Y.NodeList with the same higher-order functions that array-extras adds to Y.Array.
Methods
every
-
f
-
c
Executes the supplied function on each Node in the NodeList. Iteration stops if the supplied function does not return a truthy value. The function receives the Node, the index, and the NodeList itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
true if every item in the array returns true from the supplied function, false otherwise
find
-
f
-
c
Executes the supplied function on each Node in the NodeList, searching for the first Node that matches the supplied function. The function receives the Node, the index, and the NodeList itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
the first Node for which the supplied function returns true, or null if it never returns true
map
-
f
-
c
Executes the supplied function on each Node in the NodeList and returns a new array with the results. The function receives the Node, the index, and the NodeList itself as parameters (in that order).
Parameters:
-
f
Stringthe function to invoke
-
c
Objectoptional context object
Returns:
all return values, mapped according to the item key
partition
-
f
-
c
Partitions the NodeList into two new NodeLists, 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 Node, the index, and the NodeList itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
object with two properties: matches and rejects. Each is a NodeList containing the items that were selected or rejected by the test function (or an empty object if none).
reduce
-
init
-
f
-
c
Executes the supplied function on each Node in the NodeList, folding the NodeList 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 Node being iterated, the index, and the NodeList itself as parameters (in that order). The function must return the updated value.
Parameters:
-
init
Mixedthe initial value
-
f
Stringthe function to invoke
-
c
Objectoptional context object
Returns:
final result from iteratively applying the given function to each Node in the NodeList
reduceRight
-
init
-
f
-
c
Executes the supplied function on each Node in the NodeList, starting at the end and folding the NodeList 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 Node being iterated, the index, and the NodeList itself as parameters (in that order). The function must return the updated value.
Parameters:
-
init
Mixedthe initial value
-
f
Stringthe function to invoke
-
c
Objectoptional context object
Returns:
final result from iteratively applying the given function to each Node in the NodeList