cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

quintusCore fixed to not override 'window' when using module.exports #177

Closed benwiley4000 closed 8 years ago

benwiley4000 commented 8 years ago

While I'm sure it was well intended, using window as the name of the export target argument in the quintusCore function turns out to be a problem when using front end bundlers like Browserify or Webpack. The existence of module.exports does not negate the possibility that window will also exist (later, during browser runtime).

My change simply gets rid of the window function argument and replaces it with exportTarget. The only place exportTarget actually gets used is when var Quintus gets attached. All other references to window in this file invariably refer to the actual browser window global, which is no longer overridden, so we can leave those be.

The only problem now is that we run a shim for setAnimationFrame which might try to act on a window object that might not exist. It's fundamentally silly anyway to try to add this when we're on the server side, so I just made that shim exit early if window's type is 'undefined'.