Breaking up "for" clauses in Coffeescript
Someone recently asked this on the mailing list, here is my preferred solution:
for thing in $scope.things when thing.boolprop and !thing.otherboolprop
#Do some stuff!
becomes
fn = (thing) -> thing.boolprop and !thing.otherboolprop
for thing in $scope.things when fn(thing)
#Do some stuff!
If you export fn you can unit test it too.
Written by Martin Wawrusch
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#