What happens to the this value stored by Function.prototype.bind when the resulting function is invoked with the new operator?
answer
- one call form still gets its own object
- construction supplies the receiver by definition
- arguments survive, receiver does not
- the type test follows the target
basics
~20 sThe bound this is ignored. Construction creates a fresh object and uses that as the receiver, so new is the one call form a hard binding cannot override. Bound arguments are still prepended, and instanceof against the target function still works.
solid answer
~40 sA bound function keeps two internal pieces of state: the bound receiver and the bound arguments. When it is invoked with `new`, only the arguments are used. Construction allocates a new object and makes it the receiver, so the stored `this` is discarded — this is the single exception to the rule that a hard binding is permanent. The prototype the new object gets comes from the *target* function, not the bound wrapper, which is why the bound function has no own `prototype` property of its own. As a result `new Bound() instanceof Target` is `true`: `instanceof` on a bound function is specified to test against the target instead. Bound arguments still work as partial application of a constructor, so `Point.bind(null, 0)` gives you a constructor whose first coordinate is fixed.
code
javascript · 12 linesfunction Point(x, y) {
this.x = x;
this.y = y;
}
const Origin = Point.bind({ ignored: true }, 0);
const p = new Origin(5);
console.log(p.x, p.y); // 0 5 - bound argument survived
console.log(p.ignored); // undefined - bound receiver did not
console.log(p instanceof Point); // true
console.log(Origin.prototype); // undefined - no own prototypego deeper
Just remember the headline: using new on a bound function gives it a brand-new object as this, so the value you passed to bind is not used.
Explain why — construction defines its own receiver, so the stored one is irrelevant — and note that bound arguments are still prepended and instanceof still points at the target.
Be able to reason about the consequences in real code: a bound function has no own prototype, and binding never makes a non-constructible function constructible, so the TypeError appears at the new site.
Use it to make a point about API contracts: a function value that is both callable and constructible has two behaviours, and wrappers such as bind preserve only what the target already allowed.
## The one call form hard binding does not survive Everything about `bind` says the receiver is permanent: `call`, `apply`, a second `bind`, even using the bound function as a method all fail to change it. `new` is the exception. Constructing with `new` inherently means "create a fresh object and make it the receiver", and a stored receiver has nothing to contribute to that. ```js function Point(x, y) { this.x = x; this.y = y; } const Origin = Point.bind({ ignored: true }, 0); const p = new Origin(5); p.x; // 0 - the bound argument survived p.y; // 5 - the later argument followed it p.ignored; // undefined - the bound receiver did not p instanceof Point; // true ``` The object `{ ignored: true }` is simply never consulted. Construction goes to the target function with a freshly created object as `this`. ## What construction actually delegates A bound function object records a target function, a bound receiver and a bound argument list. It supports being called and — only if the target supports it — being constructed. On construction it forwards to the target's construct behaviour, passing the bound arguments followed by the call-site arguments, and passing along the constructor that was originally invoked so that subclassing information is not lost. A consequence people find surprising: **a bound function has no own `prototype` property**. ```js typeof Point.prototype; // 'object' Origin.prototype; // undefined ``` It does not need one, because the new object's prototype is taken from the target. That is also why `instanceof` behaves sensibly: ```js p instanceof Point; // true p instanceof Origin; // true, and it is the same test ``` `instanceof` against a bound function is specified to recurse to the target function, so both checks compare against `Point.prototype`. ## Partially applying a constructor Because the arguments survive, `bind` is a legitimate — if rarely used — way to pre-fill constructor parameters: ```js function Rect(width, height, unit) { this.width = width; this.height = height; this.unit = unit; } const SquareCm = Rect.bind(null, 10, 10); const s = new SquareCm('cm'); s.width; // 10 s.unit; // 'cm' ``` The usual caveats of `bind` partial application apply: arguments are prepended, so only a leading prefix can be fixed. ## Not every function can be constructed Binding cannot make a non-constructible function constructible. If the target cannot be used with `new`, neither can the bound result, and you get a `TypeError` at the construction site rather than at the `bind` call. Methods defined with the shorthand syntax in an object literal or a class body are among the functions that cannot be constructed, and neither can generator functions or async functions. ```js const obj = { m() {} }; const bm = obj.m.bind(obj); new bm(); // TypeError: bm is not a constructor ``` ## Why an interviewer asks this It is a precision check that follows naturally from "can you rebind a bound function?". Saying "no, never" is the answer most candidates give, and it is very nearly right; knowing the one exception shows you have read what `bind` actually specifies rather than memorised a slogan. It also connects to a real reasoning skill: `new` does not so much *override* the binding as make it irrelevant, because construction defines the receiver by definition. Any explanation of that shape earns the point, and it is more valuable than reciting the internal slot names.
- Does instanceof still identify the original function when you construct through a bound wrapper?Yes. `instanceof` on a bound function is specified to recurse to the bound target, so `new Bound() instanceof Target` is `true`, and testing against the bound function gives the same result. The bound function has no own `prototype` property at all — the instance's prototype comes from the target — which is exactly why both tests agree.
- Can binding turn a non-constructible function into a constructor?No. A bound function supports construction only if its target does. Bind an object-literal shorthand method, a class method, a generator or an async function and the `bind` call itself succeeds, but using `new` on the result throws a `TypeError` at the construction site, because the delegation to the target's construct behaviour fails.
saying these in an interview costs you the question
- Says the bound this still wins under new
- Expects new on a bound function to throw
- Thinks bound arguments are dropped during construction
- Claims instanceof fails through a bound constructor
- Believes bind makes any function constructible