re-entrant recursively implementation in JavaScript

The `o` char chain is stored in `g.q` and nullified in the end, so that this `g` can be invoked multiple times.