I find myself writing this on multiple occasions:
{ someJQueryCallback: ->
keepGoing = true
$(someSelector).each ->
unless someCondition($(@))
keepGoing = false
return false
return false unless keepGoing
moreStuff()
}
Of course, the first time, I made the rookie mistake everyone makes:
{ someJQueryCallback: ->
$(someSelector).each -> return false unless someCondition($(@))
moreStuff()
}
Ah, the perils of pretty syntax for functions. As a rookie, I forgot that in that scope, return
would exit from each
and not from someJQueryCallback
. But really, even though I'm "enlightened" now, this is still the code I want to write. I want to somehow specify "pop up the stack until you've returned from someJQueryCallback
." It's annoying to initialize and set and check a bool
flag. It adds cruft. Is there an idiomatic way to return
higher up the call stack in this way?