javascript: collapse continuations