Problem, as an interviewer would state it:
"Implement Function.prototype.myBind from scratch — matching real native bind's own documented contract, including its genuinely unusual behavior when the returned function is used as a CONSTRUCTOR."
Examples:
function greet(greeting) { return greeting + ", " + this.name; }
const g = greet.myBind({ name: "Ada" }, "Hello");
g(); // "Hello, Ada"
Clarifying questions expected:
- Unlike call/apply, bind does not invoke the function immediately — does it need to return a genuinely NEW function instead?
- Does bind need to support partial application (pre-filling some arguments, with more supplied later at call time)?
- What happens if the bound function is later called with
new— does the pre-boundthisstill apply?
Code / implementation expected: Yes — real, direct proof matching real native bind for a normal call, PLUS real, direct proof that a bound function used as a constructor correctly ignores the bound this.