UNPKG

1.11 kBJavaScriptView Raw
1var _arity =
2/*#__PURE__*/
3require("./internal/_arity");
4
5var _curry2 =
6/*#__PURE__*/
7require("./internal/_curry2");
8/**
9 * Creates a function that is bound to a context.
10 * Note: `R.bind` does not provide the additional argument-binding capabilities of
11 * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
12 *
13 * @func
14 * @memberOf R
15 * @since v0.6.0
16 * @category Function
17 * @category Object
18 * @sig (* -> *) -> {*} -> (* -> *)
19 * @param {Function} fn The function to bind to context
20 * @param {Object} thisObj The context to bind `fn` to
21 * @return {Function} A function that will execute in the context of `thisObj`.
22 * @see R.partial
23 * @example
24 *
25 * const log = R.bind(console.log, console);
26 * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3}
27 * // logs {a: 2}
28 * @symb R.bind(f, o)(a, b) = f.call(o, a, b)
29 */
30
31
32var bind =
33/*#__PURE__*/
34_curry2(function bind(fn, thisObj) {
35 return _arity(fn.length, function () {
36 return fn.apply(thisObj, arguments);
37 });
38});
39
40module.exports = bind;
\No newline at end of file