Return a new function that calls the original with call: Function.prototype.myBind = function(context, ...presetArgs) { return (...args) => this.call(context, ...presetArgs, ...args); }.
How do you implement a polyfill for bind in an interview?
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.
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.
new (highest) > bind > call/apply > implicit (method call) > default (plain call). Arrow functions are an exception: they use lexical this and ignore all of these rules.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.