Skip to content

OutputNot attempted

bind vs call, double bind, new on a bound fn

function who() {
return this?.n;
}
const a = { n: 'a' };
const b = { n: 'b' };
const bound = who.bind(a);
console.log(bound(), bound.call(b), who.bind(a).bind(b)());
function Person(name) {
this.name = name;
}
const BoundPerson = Person.bind({ name: 'ignored' });
const p = new BoundPerson('Real');
console.log(p.name, p instanceof Person);

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

bind is permanent: call/apply and a second bind cannot override it → a a a. But new beats bind: the bound this is ignored and a fresh object is created, still instanceof Person.