marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch 11, Callback section, possible rewrite about types and handlers #397

Closed dhollinden closed 6 months ago

dhollinden commented 6 years ago

I'm re-reading ch 11. The second time through, I realized I had difficulty here, starting with this paragraph:

"Each message is tagged with a type, which determines how it is handled. Our code can define handlers for specific request types, and when such a request comes in, the handler is called to produce a response."

The term "handler" is frequently used later on, but it's significance slipped past me in the above. I also didn't understand the distinction between types and handlers because the text states, "Our code can define handlers..." yet the function is named defineRequestType. I wonder if you might consider a re-write similar to this:

"Each message is tagged with a type, which determines how it is handled. Our code can define types and associate each one with a handler function. That way, when a specific request type comes in, it's associated handler is called to produce a response."

Then further down, this paragraph:

"The defineRequestType function defines a new type of request. The example adds support for "note" requests, which just sends a note to a given nest. Our implementation calls console.log so that we can verify that the request arrived. Nests have a name property that holds their name."

could be revised like this:

"The defineRequestType function defines a new type of request. The example adds support for "note" requests, which just sends a note to a given nest. The handler for "note" requests calls console.log so that we can verify that the request arrived. Nests have a name property that holds their name."

Thanks

marijnh commented 6 months ago

This chapter has been redone entirely in the 4th edition.