A pitfall in Javascript


Today (Dec 14 2012) I wrote below javascript:

function getWindowDimensions()
    { inner : { width : window.innerWidth, height window.innerHeight } };

But strangely it has syntax error in the Android browser based on WebKit.

After try-and-err, I found the root cause: Javascript uses newline as a statement terminator. This means I must write “return” and the object definition at least with the opening brace on the same line.

Well, it’s a BIG pitfall!