Skip to content
MitalAshok edited this page Nov 6, 2016 · 2 revisions

Methods Defined Here

Returns a version of the function that has given parameters prefilled and passes given parameters through to the original, denoted by placeholders.

Parameters

this::partial(staticParams)
  • this: {T}
  • ...staticParams: (any) The prefilled parameters.

Example Usage

Unary parseInt

parseInt::partial(_)("10", 2) // 10

Hexadecimal parseInt

parseInt::partial(_, 16)("10") // 16

Fill Only the Second Argument

function foo (a, b, c, d) {
  console.log(a, b, c, d);
}

foo::partial(_, 2, ___)(1, 3, 4) // logs "1 2 3 4"

Fill Only the Second Last Argument

function foo (a, b, c, d) {
  console.log(a, b, c, d);
}

foo::partial(___, 3, _)(1, 2, 4) // logs "1 2 3 4"

Compose a Prototype Method

const slice1 = Array.prototype.slice::partial(1, ___);
[1, 2, 3, 4]::slice1() // [2, 3, 4]