-
Notifications
You must be signed in to change notification settings - Fork 0
attach
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]