API Docs for: 1.0.0
Show:

NodeList~extras2 Class

Augments Y.NodeList with the same higher-order functions that array-extras adds to Y.Array.

Item Index

Methods

every

(
  • f
  • c
)
Boolean

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 Function

    the function to execute on each item

  • c Object

    optional context object

Returns:

Boolean:

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

find

(
  • f
  • c
)
Node

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 Function

    the function to execute on each item

  • c Object

    optional context object

Returns:

Node:

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

map

(
  • f
  • c
)
Array

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 String

    the function to invoke

  • c Object

    optional context object

Returns:

Array:

all return values, mapped according to the item key

partition

(
  • f
  • c
)
Object

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 Function

    the function to execute on each item

  • c Object

    optional context object

Returns:

Object:

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
)
Mixed

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 Mixed

    the initial value

  • f String

    the function to invoke

  • c Object

    optional context object

Returns:

Mixed:

final result from iteratively applying the given function to each Node in the NodeList

reduceRight

(
  • init
  • f
  • c
)
Mixed

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 Mixed

    the initial value

  • f String

    the function to invoke

  • c Object

    optional context object

Returns:

Mixed:

final result from iteratively applying the given function to each Node in the NodeList