June 2014
Intermediate to advanced
696 pages
38h 52m
English
An interesting problem related to asynchronous callbacks is closure. Closure is a JavaScript term that indicates that variables are bound to a function’s scope and not to the parent function’s scope. When you execute an asynchronous callback, the parent function’s scope may have changed (for example, when iterating through a list and altering values each iteration).
If a callback needs access to variables in the parent function’s scope, you need to provide closure so that those values are available when the callback is pulled off the event queue. A basic way of doing this is to encapsulate an asynchronous call inside a function block and pass in the variables that are needed.
The code in Listing 4.6 illustrates ...
Read now
Unlock full access