Question about passing functions as parameters to events. Why does this code work?

Question about passing functions as parameters to events. Why does this code work?

  1.         function setup(bVal) {
                $("#button2").click(function() {
                    if (bVal == false)
                        alert("false");
                    if (bVal == true)
                        alert("true");
                });
            }






I then call setup from $(document).ready. It behaves just like I want it to. But this puzzles me. How can the anonymous function evaluate bVal when the button is clicked?