June 2014
Intermediate to advanced
696 pages
38h 52m
English
Most callbacks have automatic parameters passed to them, such as an error or a result buffer. A common question when working with callbacks is how to pass additional parameters to them from the calling function. The way to do this is to implement the parameter in an anonymous function and then call the callback with parameters from the anonymous function.
The code in Listing 4.5 shows how to implement callback parameters. There are two sawCar event handlers. Note that the sawCar event only emits the make parameter. The first event handler, on line 16, implements the logCar(make) callback handler. To add a color for logColorCar(), an anonymous function is used in the event handler defined in lines 17–21. ...
Read now
Unlock full access