Keeping this When You Pass a Method
Early Lanes has two lanes. Python’s LaneSession books each pass while a lane is free; once both are
taken, it calls on_full, if there is one, with the swimmer’s name. Give it a waitlist’s method, and see what
JavaScript does to the keyword this.
In JavaScript, the constructor takes the callback in an options object,
{ onFull = () => {} } = {}, with a do-nothing arrow as its default, so book() calls
this.onFull(pass.swimmer.name) without a check, and booked = []; becomes a field.
The callback is a waitlist’s add(), which puts a name on the list and prints the place. Python
passes on_full=waitlist.add, a bound method that carries its waitlist along, and prints two
check-ins, then Grace’s place on the waitlist.
The waitlist ports like any class, with names = []; as a field. A line-by-line port of the run
passes the same method in the options object: