Skip to the page

Polyfills & utilities · Build it

bind / call / apply polyfills

The interviewer asks

Write Function.prototype.myBind. Make it work with new. Then do myCall without using call/apply.

Then

Follow-ups the interviewer asks next

  1. new on the bound function must ignore the bound this.
  2. myCall: attach the fn to ctx under a Symbol key, invoke it, delete it.
  3. null/undefined ctx means globalThis in sloppy mode.
  4. Preserve prototype and length.

The answer

What a strong answer covers

  • Function.prototype.myBind = function (ctx, ...bound) {
  • const fn = this;
  • function boundFn(...args) {
  • return fn.apply(this instanceof boundFn ? this : ctx, [...bound, ...args]);
  • }
  • boundFn.prototype = Object.create(fn.prototype);
  • return boundFn;
  • };
  • Partial application of the leading args
  • Use a Symbol key in myCall to avoid clobbering existing properties

The red pen

Common traps

Avoid:using an arrow inside so new breaks; mutating ctx with a string key.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview