Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including weak-bind with all npm packages installed. Try it out:

var weakBind = require("weak-bind")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

weak-bind v0.0.1

An overridable equivalent for Function.prototype.bind


Once a function is bound, there's no way of un-binding it - i.e. to run it under a different context. So, this module is an equivalent to Function.prototype.bind, which still allows for the function context to be overridden with bind, call and apply.


$ npm install weak-bind


bind(fn, context, [args...]) is equivalent to fn.bind(context, [args...]), but reversible.

var bind = require('weak-bind')
  , first = { x: 'first' }
  , second = { x: 'second' }

function getX() {
  return this.x;

getX(); // NaN

bind(getX, first)() // "first"
getX.bind(first)()  // "first"

bind(getX, first).bind(second)() // "second"
getX.bind(first).bind(second)()  // "first"


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free