Support for environment with `global` and `window`

Node-webkit has a global `global` object, while the global `this` is the
`window` object. Overwriting `global` with `window` breaks a lot of
things.
Merge pull request #1159 from michalc/master

Support for environment with `global` and `window`