liveBook · Manning

This

As explained in Build a Frontend Web Framework (From Scratch)

The JavaScript binding that determines the object supplied as the this value during a function call.

The JavaScript this value determines which object a function call supplies as its context. In component code, the intended context is often the component instance, because render callbacks and event handlers need access to state and methods. section 9.3.1 section 11.2.1

Component implementations use this to connect callbacks with the objects they operate on:

  • An event handler can call component methods such as this.updateState(). section 10.5
  • A parent’s handler must retain the parent component as its this value when a child emits an event. section 11.2.1

Binding a render callback

A callback passed to defineComponent() is not automatically a class method. Calling render() directly can make this refer to Window, or undefined in strict mode, causing this.state.count to fail. Calling render.call(this) supplies the component instance explicitly.

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Explains callback binding, contrasts class methods, and implements explicit binding with call(), without surveying all JavaScript binding rules.
Examples
Uses a counter component, an increment button, and a parent handling a child’s emitted event.
What it assumes
Assumes basic JavaScript functions and classes while distinguishing class methods from functions passed as callbacks.
What you can do after
Apply it via Function.call to preserve component context in render callbacks and event handlers.
How it connects
Connects function calls, component instances, event handlers, component state, props, and parent-child communication.

Also explained in

Compare how 4 books explain this →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.