Fix potential ReferenceError in non-browser env

Testing for `window` would throw if undeclared.
Also, avoid repeating feature check.
Merge pull request #758 from stevoland/master

Fix potential ReferenceError in non-browser env