Implement your own bind (Function.prototype.myBind).
Quick answer
Return a new function that calls the original with a fixed `this` and merged arguments via apply.
In detail
Store the original function and the bound context, then return a wrapper that combines the pre-set args with the new call args and invokes the original with the bound `this`. A clean test of closures plus understanding of how bind works.
1Function.prototype.myBind = function (ctx, ...preset) {
2 const fn = this;
3 return function (...later) {
4 return fn.apply(ctx, [...preset, ...later]);
5 };
6};
7function greet(g) { return `${g}, ${this.name}`; }
8greet.myBind({ name: "Arun" }, "Hi")(); // "Hi, Arun"Why interviewers ask this: Common product-company question combining `this` + closures.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299