Why do external functions get executed immediately? : <p>I have a declared function in my code. I want to call this function whenever I click on an item. When I bind it to this item, it gets executed immediately, and the on click event does not trigger.</p>

<p>However, when I declare the function in the on click binding, it works fine.</p>

<p>I want to declare the function somewhere else first, and then call it when the click event happens</p>

<pre><code>function test2() {
  alert('test2');
}

$('body').on('click', '#test1', function() { alert('test1'); });
$('body').on('click', '#test2', test2());
</code></pre>

<p><a href="https://jsfiddle.net/ag66r950/" rel="nofollow">https://jsfiddle.net/ag66r950/</a></p>
