jshint cleanup

These changes are syntax changes recommended by jshint; I did not blindly trust the tool and frequently ignored its suggestions where I knew the tool didn't have the full story. All changes should result in code that runs the same way but is more formally correct; in the cases of moving function definitions outside loops so that new functions aren't created at each iteration, the code should even run faster, with less memory usage.
~~I had my Eyeo Contributor License Agreement here inline but decided I'd rather not let everyone on the Internet know my home address.~~