Why second code doesnt work?


#1



why it doesn't work for second code?


//First Code
var main=function(){
    $('.pull-me').click(function()
    {
        $('.panel').slideToggle('slow');
    });
}

//Second code
function main(){
    $('.pull-me').click(function()
    {
        $('.panel').slideToggle('slow');
    });
}

$(document).ready(main); //for first code,it works
$(document).ready(main()); //for second code,it doesn't work


#2

Use $(document).ready(main); for the second code.


#3

why i cant use main()?
it just doesnt make sense for me because ready(function(){}) works and ready(main()) doesnt work


#4

There is a big difference between the two. ready(function(){}) means you are defining an anonymous function and passing the definition to ready. Using main() means execute the function and pass the result to ready() function.