I have an input which when im clicking – i want to see alert with ‘1,2,3,4…’ (each press)
<input type='button' value='press' onclick='Clicked();' />
<script>
var t
function Clicked()
{
t=func;
t();
}
function func()
{
var count=0;
return new function () // <=== new or not new ???
{
count++;
alert(count);
}
}
</script>
If im adding the 'new' in the return and click , it says : '1,1,1,1,...'
If im removing the ‘new’ it doesnt work…
My goal is to use this to get : ‘1,2,3,4…’
Can someone explain to me what happens ?
You need to use the returned function:
Example