How does super work as an object?

I think its worth pointing out that MDN does a bad job with the role of receiver with respect to set. It's description for the receiver argument is simply:

The value of this provided for the call to target if a setter is encountered.

This ignores the very important fact that when present, if not calling a setter, the receiver becomes the target for the property being set.

const a = { x: 1 }
const b = { x: 2 }
Reflect.set(a, 'x', 3, b) // sets on b, not a
console.log({a, b}) // a: { x: 1 }, b: { x: 3 }}

Especially important in this particular case since that's exactly what's happening with super and this in:

Reflect.set(Reflect.getPrototypeOf(B.prototype), "x", 3, this); // super.x = 3;
1 Like