Make browserify compatible

With the existing check for the namespace on which to export, this module behaved badly when attempting use with browserify. Rather than export on the `exports` object, it would attach it to the global `window`.

This pull request switches around the check, looking for `exports` first, so that if both `exports` and `window` exist, the module contents are attached to `exports`.