javascript multiple binds

In javascript, if we bind multiple times, only the first bind takes in the provided this value. That is because the bind function returns a new function which doesn’t have this anymore. Subsequent binds won’t have any effect on the original this.

// NOT the real bind; just an example
Function.prototype.bind = function(ctxt) {
    var fn = this;
    return function bound_fn() {
        return fn.apply(ctxt, arguments);
// no more 'this' in my_bound_fn
my_bound_fn = original_fn.bind(obj);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s