Skip to content
Subhajit Sahu edited this page Jul 29, 2022 · 2 revisions

Attach prefix arguments to leftmost parameters of a function.

Alternatives: attach, attachRight.
Similar: bind, attach.


function attach(x, ...prefix)
// x:      a function
// prefix: prefix arguments

const xfunction = require('extra-function');


var fn = xfunction.attach(Math.min, 100);
fn(180, 130);  // Math.min(100, 180, 130)
// → 100

var array = [1];
var fn = xfunction.attach((...vs) => array.push(...vs), 10, 10);
fn(1, 2, 3);  // array.push(10, 10, 1, 2, 3)
array;
// → [1, 10, 10, 1, 2, 3]


References

Clone this wiki locally