Move singleton JS code into 'singletons' object

This change will make it much simpler to write custom output bindings that are similar to htmlOutputBinding, that use singletons.

This works with the with the dynamic_singletons test app as well as the setinput app.