1-liners
Version:
Useful oneliners and shorthand functions
16 lines (15 loc) • 458 B
JavaScript
/**
* @module 1-liners/bind
*
* @description
*
* Binds a context to a function. Same as [`fun.bind(thisArg[, arg1[, arg2[, ...]]])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
*
* @example
*
* const bind = require('1-liners/bind');
*
* setTimeout(bind(console, ['Hello'], console.log), 2000); // => 'Hello' (after 2s)
*
*/
export default (thisArg, args, fun) => fun.bind(thisArg, ...args);