Skip to content

this and prototypes

Where this comes from

`this` is decided by how a function is called, and a property is looked up by walking a chain. · 12 minutes

A method is a function stored on an object, and the function does not know which object that is. `this` is filled in by the call: `account.read()` passes `account` as the receiver because it was called through `account`. The same function called any other way gets a different `this`, or none.

const read = account.read; read(); — where read returns this.balance. What happens?