UNPKG

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