-
Notifications
You must be signed in to change notification settings - Fork 0
attachRight
Subhajit Sahu edited this page Aug 7, 2022
·
1 revision
Attach suffix arguments to rightmost parameters of a function.
Alternatives: attach, attachRight.
Similar: bind, attach.
function attachRight(x, ...suffix)
// x: a function
// suffix: suffix arguments
const xasyncfn = require('extra-async-function');
var fn = xasyncfn.attachRight(Math.min, 100);
fn(180, 130); // Math.min(180, 130, 100)
// → 100
var array = [1];
var fn = xasyncfn.attachRight((...vs) => array.push(...vs), 10, 10);
fn(1, 2, 3); // array.push(1, 2, 3, 10, 10)
array;
// → [1, 1, 2, 3, 10, 10]