Skip to content
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]


References

Clone this wiki locally