Ramda.js R.bind() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that is bound to a context (official Ramda docs). Pass a function and a thisObj; every later call runs fn with this fixed to that object. Common use: safe console.log inside R.pipe / R.tap.

Stable since v0.6.0: R.bind is a core Ramda helper — not deprecated, experimental, or non-standard. It pins this only; it does not pre-bind extra arguments like native Function.prototype.bind. Use R.partial for that.

Syntax

Call R.bind. Start with this line.

Ramda
R.bind(fn, thisObj)
CallWhat it does
R.bind(fn, thisObj)Primary signature.
R.bind(...)Call the function helper.

Prefer import { bind } from "ramda" when you want a named import.

Library declarations
Ramda
R.bind(fn, thisObj)

Parameters

ParameterDescription
fnRequired. Function to run with a fixed this
thisObjRequired. Context object for this

Return Value

Return ValueDescription
*New function; same args as fn, fixed this

Ramda Examples

Example 1 — Official Pipe Logger

Bind a logger and peek with R.tap — same idea as the Ramda docs.

Ramda
const captured = [];
const logger = {
  log(value) { captured.push(JSON.stringify(value)); }
};

const log = R.bind(logger.log, logger);
const result = R.pipe(
  R.assoc('a', 2),
  R.tap(log),
  R.assoc('a', 3)
)({ a: 1 });

console.log(result);    // { a: 3 }
console.log(captured);  // ['{"a":2}']
Try It Yourself

How It Works

  1. Bind the method. R.bind(logger.log, logger) keeps this on logger.
  2. assoc then tap. Value becomes {a: 2}; tap logs it and passes it through.
  3. Final assoc. Pipeline returns {a: 3} — tap does not change the value.
  4. Why bind. A bare method as a callback can lose this; bind prevents that.

Example 2 — Restore a Lost this

Extracting a method drops the receiver; R.bind puts it back.

Ramda
const person = {
  name: 'Ada',
  greet() {
    return this && this.name ? this.name : 'no-this';
  }
};

console.log(person.greet());                 // "Ada"
console.log(person.greet.call(undefined));   // "no-this"
console.log(R.bind(person.greet, person)()); // "Ada"
Try It Yourself

How It Works

  1. Method call. person.greet() sets this to person → "Ada".
  2. Detached call. Without a receiver, this is missing → "no-this".
  3. Bound call. R.bind(…, person) locks the receiver permanently.
  4. Safe callback. Pass the bound function anywhere without losing name.

Example 3 — vs Native bind and R.partial

R.bind does not pre-fill arguments — that is native bind or R.partial.

Ramda
const pair = (a, b) => [a, b];

console.log(pair.bind(null, 'pre')('x'));     // ["pre", "x"]
console.log(R.bind(pair, null)('x'));         // ["x", undefined]
console.log(R.partial(pair, ['pre'])('x'));   // ["pre", "x"]
Try It Yourself

How It Works

  1. Native bind. Extra args after this are prepended → ["pre", "x"].
  2. R.bind. Only sets this; 'x' is the first real arg → second is missing.
  3. R.partial. Pre-fills arguments without caring about this.
  4. Docs note. Ramda explicitly omits native-style argument binding.

Example 4 — Map with a Bound Method

Keep this.prefix working when a method is used as a map callback.

Ramda
const box = {
  prefix: '#',
  tag(n) { return this.prefix + n; }
};

console.log([1, 2, 3].map(R.bind(box.tag, box)));
// ["#1", "#2", "#3"]
Try It Yourself

How It Works

  1. Method needs this. tag reads this.prefix.
  2. map detaches. Passing box.tag alone would lose box.
  3. Bind first. R.bind(box.tag, box) keeps the receiver.
  4. Result. Each number gets the # prefix.

Example 5 — Bind Once, Call Many Times

Reuse a bound incrementer so this stays on the same counter.

Ramda
const counter = {
  n: 0,
  inc() {
    this.n += 1;
    return this.n;
  }
};

const inc = R.bind(counter.inc, counter);
console.log(inc());       // 1
console.log(inc());       // 2
console.log(counter.n);   // 2
Try It Yourself

How It Works

  1. Bind once. inc always mutates the same counter.
  2. First call. n goes 0 → 1.
  3. Second call. n goes 1 → 2.
  4. Shared state. counter.n matches — the bound function and object stay linked.

Browser & Runtime Support

R.bind() is ordinary JavaScript once Ramda is loaded. It needs no special browser API — only a JS runtime that can run Ramda (v0.6.0+).

✓ Ramda 0.6.0+ · Any JS runtime

Ramda.js R.bind()

Works in every modern browser and runtime where you can load Ramda (CDN or npm). Internet Explorer needs a build that targets that environment; there is no native IE API to polyfill.

100% With Ramda loaded
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.bind() Universal

Bottom line: Safe in any project that includes Ramda 0.6.0 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno.

Frequently Asked Questions

R.bind(fn, thisObj) returns a new function that calls fn with this permanently set to thisObj. Later calls can pass arguments as usual. The docs sample is const log = R.bind(console.log, console); then R.tap(log) is safe inside a pipe.
const log = R.bind(console.log, console); R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} and logs {a: 2}. Added in v0.6.0. See also R.partial.
Both pin this. Native fn.bind(thisObj, a, b) also prepends extra arguments. R.bind does not: it only takes the function and the context. For pre-filled arguments, use R.partial.
Some hosts require console.log to run with console as this. Passing console.log as a bare callback can throw or no-op. R.bind(console.log, console) makes a callback that always has the right this.
Yes. The type is (* → *) → {*} → (* → *), so R.bind(fn)(thisObj) works the same as R.bind(fn, thisObj).
No. R.bind is a stable Ramda function helper from v0.6.0. It is not deprecated, experimental, or non-standard.

Next: R.call()

Invoke a function with arguments listed one by one.

R.call() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful