Create JavaScript array of function pointer, without calling it
Posted
by sibidiba
on Stack Overflow
See other posts from Stack Overflow
or by sibidiba
Published on 2010-04-16T22:42:50Z
Indexed on
2010/04/16
22:53 UTC
Read the original article
Hit count: 170
JavaScript
|JSON
I have the code below. I would like to have an array (buttons) with a single element pointing to the a function (closeFlag).
<script type="text/javascript">
var closeFlag = new function() {
alert('Clicked');
}
var buttons = {
'OK': closeFlag
}
</script>
However, when loading the page the alert immediately pops up. When the array is constructed, instead of using it as a pointer, JavaScript calls my function. Why? What mistake, misconception do I have?
© Stack Overflow or respective owner