I spent a fair bit of time on this Javascript issue (you can tell I am a JS noob):
Take some well written Javascript code like this example of the Revealing Module P
Javascript has some strange bits to it and one is that the position of the brackets matters - keep the opening one on the same line as the code
http://encosia.com/in-javascript-curly-brace-placement-matters-an-example/