-
Notifications
You must be signed in to change notification settings - Fork 0
attach
Subhajit Sahu edited this page Aug 7, 2022
·
1 revision
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 xasyncfn = require('extra-async-function');
var fn = xasyncfn.attach(Math.min, 100);
fn(180, 130); // Math.min(100, 180, 130)
// → 100
var array = [1];
var fn = xasyncfn.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]