1.0.2 • Published 5 years ago

farr-this v1.0.2

Weekly downloads
1
License
Unlicense
Repository
github
Last release
5 years ago

VersionBuild Status codecov

license JavaScript Style Guide


farr-this

Documentation

Please see: Documentation

Arrays of bound functions with shared this parameters.

This module exports a class FarrThis, that extends the native Array class (via its parent class Farr).

Anytime an array-index-valued property of a FarrThis is set, the provided value gets filtered:

  • If the value is a function, it's bound.
  • If the value is not a function, it's replaced by a new bound function that produces the value when called.

This means that FarrThis arrays only store bound function elements or empty slots.

this Binding

Each function element has a bound this property corresponding to a plain object with some common parameters:

  1. a: the containing instance (FarrThis)
  2. i: the index of this element in the containing instance (integer)
  3. f: a reference to this element (function)
  4. o: any user-specified object, also accessible as the o property of the containing instance ('object')

Farr

For convienience, this module also exports its parent class, Farr).


Installation

Run npm install farr-this

Usage

import { FarrThis as Ft } from 'farr'
const n = 5
function e () {
  return this.i
}
const a = new Array(n).fill(e)
const f = new Ft({ a })
f.push(e)
const result = await f.all() // [ 0, 1, 2, 3, 4, 5 ]

Testing

Run npm test. This will also trigger a download of the tests from the farr dependency. These tests will be stored and run in the test/farrtest directory, so don't put anything there.

Incompatibilities

The following features of farr are incompatible with farr-this:

  • generated: all elements undergo mutation
  • givenFunc: all elements undergo mutation
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago