verge icon indicating copy to clipboard operation
verge copied to clipboard

Add "guard" parameters

Open ryanve opened this issue 12 years ago • 0 comments

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.

ryanve avatar Dec 16 '13 02:12 ryanve