Facebook Pixel

Can you re-bind a bound function in JavaScript?

No. The first bind wins. Once a function is bound, calling bind again on the bound function does not change this. This is a common interview trick question.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in call, apply, and bind: Interview Preparation Guide

What each does (call: immediate comma args, apply: immediate array args, bind: returns function), how to implement polyfills, use cases (method borrowing, fixing this, partial application), precedence (new > bind > call > implicit > default), arrows ignore them, and re-binding is not possible.

Return a new function that calls the original with call: Function.prototype.myBind = function(context, ...presetArgs) { return (...args) => this.call(context, ...presetArgs, ...args); }.

Predict the output of code using call/apply/bind with a specific this and arguments. For example: foo.call(obj, 1, 2) where foo returns this.x + a + b and obj.x is 10. Answer: 13.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.