Suppose each object produced by a prisoner factory must answer the same question: will it snitch? A method gives the object a function to answer it. Calling `prisoner.snitch()` returns `true` or `false`, so the simulator can use each new prisoner through the same interface. section 19.1
Methods can be written on objects or in a class body. The syntax looks similar, but the surrounding rules differ:
- An object yielded by a generator can contain `snitch() { return true }`. Each yield provides a new object with that method. section 19.1
- A class can declare `fetch() { /* fetch records */ }`. Class methods can accept parameters and use `this` to refer to the instance. section 27.1
- Do not write `fetch: function() {}` in a class body or put commas between class methods. Those object-literal conventions cause syntax errors there. section 27.1
A method passed as a callback
Imagine `fetch()` calls `ajax(this.url, this.handleNewRecords)`. The ajax library later invokes the callback, but `handleNewRecords` is not automatically bound to the data-store instance. Its `this.records = records` therefore will not store the records on that instance. Instead, pass `records => this.handleNewRecords(records)`: the arrow function makes the call through the instance when the records arrive. section 27.4
Listing 27.2. Using unbound methods as callbacks
Trace the two marked lines: first the method is handed to `ajax` as a callback; later its use of `this` no longer points to the instance. section 27.4



















