function as method argument in jquery without writing the entire function definition -


from understand, in jquery, when method requires function argument can't invoke predefined function this:

$('#target').click(myfunction()); 

...because "myfunction()" parsed , replaced value returned function...which no longer function.you have put entire function definition, in anonymous function:

$('#target').click(function() {    alert('handler .click() called.'); }); 

...so, there way of invoking function it's required argument?

you understand correctly. true not in jquery, how javascript works. when function needed argument, have give function argument, , not result of invocation. can use this:

$('#target').click(myfunction); 

but alert need anonymous function because passing argument.


Comments

Popular posts from this blog

python - Why doesn't list have safe "get" method like dictionary? -

razor - Is this a bug in WebMatrix PageData? -

sql server - Stored procedure -