Alter prefix.js to check that window is a window and that require exists

Hi, this is related to #40 and #41 and makes to library compatible with the [requirejs optimizer](http://requirejs.org/docs/optimization.html). It preserves compatibility with commonjs and allows for its continued use with AMD loaders via a shim.

Thoughts and feedback welcome. Thanks.