added support for commonjs modules

Hey there,

This PR adds support for commonjs modules, browserify etc, sometimes used in environments where the 'window' object isn't available, but JSON is.

Steve