jshint warning “Don’t make functions within a loop”
Ever get JSHint warning “Don’t make functions within a loop” with your node.js code? I do and my OCD strives to stamp out this warning in my code.
A typical situation for me is I want to augment a model before returning from GET REST call. Here is a stripped down example:
Run jshint on the above code I get
Using ‘Q’ for promises I reworked the code to fire off all the FakeRedis calls and stuff the returned promises in an array. Then I use Q.all([promises]) to wait for all the FakeRedis calls to complete and then augment the model with the result.
If you have a better way of handling this situation I would love to hear from you!