Possible Duplicate:
javascript syntax: function calls and using parenthesis
t.onclick = doSomething
t.onclick = doSomething()
what’s the different between the two event registrations?
sometimes I would confuse about them,add an parentheses seems would not cause big problem?
The first one assigns a reference to
doSomethingto theonclickproperty. The second assigns the return value ofdoSomething. That’s unlikely to be what you want, unlessdoSomethingreturns a function.Assign a reference:
Assign the return value:
Assign a returned function: