Code is as follows:
<body>
<a href="javascript:;" id="test">hello</a>
</body>
<script type="text/javascript">
document.getElementById("test").addEventListener("click", function () {
test()
}, false)
function test() {
var postTypes = new Array('hello', 'there')
(function() { alert('hello there') })()
}
</script>
This will throw an "Uncaught TypeError: object is not a function". If I wrap the anonymous function call/invocation in another set of parentheses it will execute the alert, but still give me an error. If I put a semi-colon after the "var postTypes" definition then it will completely fine.
I was led to believe that javascript does not require semi-colons, so I'm making a guess that there is some weird associativity rules of function application that I am not fully understanding. I hope someone can give me the answer to why I am getting this error.
Thanks.