kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.32k stars 198 forks source link

Box2D.js does not work in strict mode #42

Open AshleyScirra opened 10 years ago

AshleyScirra commented 10 years ago

I need to use Box2D.js in a strict-mode environment. Put "use strict"; at the top of box2d.js and it fails with "cannot set property 'Module' of undefined", due to the use of "this" to refer to global namespace which is not allowed in strict mode.

To work around this I have to remove a weird try/catch which tries to assign this.Module (why?) and remove the assignment of this.Box2D at the end. Then I add "var Module = {};" to the top.

Further the script proceeds to clobber pretty much every two-letter global variable, which causes random weird errors if incorporated in to a large existing JS codebase. It really ought to go in its own closure.

otse commented 8 years ago

How to prevent this?