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

Bind this-object, and optional prefix arguments to a function.

Similar: bind, [attach].


function bind(x, ths, ...prefix)
// x:      a function
// ths:    this object to bind
// prefix: prefix arguments
const {bind} = require('extra-function');


var array  = [1];
var fn = bind(Array.prototype.push, array);
fn(2, 3, 4);  // push(2, 3, 4)
array;
// → [1, 2, 3, 4]

var array  = [1, 2, 3, 4];
var fn = bind(Array.prototype.splice, array, 1);
fn(2);  // splice(1, 2)
array;
// → [1, 4]


References

Clone this wiki locally