Don't clobber global scope

Also generated JS has `use strict` directive, and fixed a missing `var`
when printing `for` statements.