Skip to content

Add "guard" parameters #9

@ryanve

Description

@ryanve

Methods whose signature is (value [, number]) cannot be used directly as array iterators whose 2nd argument is the array index. It'd be useful add guard params that allow the following examples to work with standard array methods:

array.filter(verge.inViewport)
array.some(verge.inViewport)
array.map(verge.rectangle)

We can achieve this similar to how underscore uses guard params. For example:

function rectangle(el, pad, guard) {
  pad = !guard && +pad || 0; // number and not NaN

We had some partial undocumented support for this in some versions. We should add it to all applicable methods with this signature and document the usage.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions