1-liners
Version:
Useful oneliners and shorthand functions
23 lines (20 loc) • 581 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)
*
*/
;
exports.__esModule = true;
exports["default"] = function (thisArg, args, fun) {
return fun.bind.apply(fun, [thisArg].concat(args));
};
module.exports = exports["default"];