I don't know how it works. But the underscore library has a chain function.
This can chain an endless list of functions, but won't end the closure automatically.
You need to call the result() function.
But you could look a their code to see how they did it.
Underscore.js[
^]