Facebook Pixel

What should I know about call, apply, and bind for an interview?

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.

Verify This Answer

Cross-check this information using these trusted sources:

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

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.

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?

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.