Possible Duplicate:
Why does click event handler fire immediately upon page load?
There is a gap in my understanding of Javascript's function so I have trouble understanding why my event handlers get fired automatically if I define it without an anonymous wrapper.
HTML
<a href="#" id="change-html">Change HTML</a>
Javascript #1
var btn = $('#change-html');
btn.click(bindClick(btn)); // bindClick gets executed right away and only once
function bindClick(source){
console.log('get here');
}
Javascript #2
var btn = $('#change-html');
btn.click(function(){
bindClick(btn); // bindClick is only executed on the anchor's click event
});
function bindClick(source){
console.log('get here');
}