You can easily chain methods along with variables to find a highly readable, and totally sensible scope chain.
We have seen how closures can be used in Javascript before. Let us see some more practical usage scenarios.
Consider the below closure -
|
|
What do you think will happen if we put more inner functions?
|
|
With each iteration, we remember the variable and proceed to the next. We therefore end up multiplying all products from left to the right. We could have done it separately as we did before, or neatly chain it like depicted in the above code.