A pitfall in Javascript

2013年2月9日

Today (Dec 14 2012) I wrote below javascript:


function getWindowDimensions()
{
    return
    { 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!

留下您的评论