[jQuery] Re: anonymous function and code reusing

2009-06-15 Thread Ricardo
That's why bind() supports a 'data' argument: $(document).ready(function(){ $(#earth).bind('click', { stuff: 'param1' }, myFunction); $(#moon).bind('click', { stuff: 'param2' }, myFunction); function myFunction(e){ alert( e.data.stuff ); }; }); see here:

[jQuery] Re: anonymous function and code reusing

2009-06-14 Thread waseem sabjee
function reuse(param) { $(#moon).click(function(){ if(param == 1) { alert(do something); } else { alert(Access Denied); } }); } On Sat, Jun 13, 2009 at 6:53 PM, jwc droghe.digit...@gmail.com wrote: Hi guys, apologize for posting again the same topic. I

[jQuery] Re: anonymous function and code reusing

2009-06-14 Thread Mirko Galassi
$(document).ready(function(){ $("#moon").click(function() { myFunction("param"); }); $("#earth").click(function() { myFunction("param2"); }); }); It works perfectly! Thanks MorningZ ha scritto: "I thought it should have worked but it doesn't" You cannot pass params like that in a

[jQuery] Re: anonymous function and code reusing

2009-06-14 Thread Mirko Galassi
Interesting someone has suggested it $("#moon").click(myFunction("param")); $("#earth").click(myFunction("param2")); it involves less code, and it is probably faster because doesn't have condition statements that need to be executed. Do you agree? waseem sabjee ha scritto: function

[jQuery] Re: anonymous function and code reusing

2009-06-14 Thread Kelly
Mirko, You were missing a small but significant point. The function you call must return a function. $('#moon').click(myFunction('param')); $('#earth').click(myFunction('param2')); function myFunction(param) { return function() { alert(param); }; } I suggest studying this pattern closely;

[jQuery] Re: anonymous function and code reusing

2009-06-14 Thread Mirko
Thanks Kelly for the suggestion But using a return param in a function doesn't work completely because the function has a problem in another case that I didn't mentioned before. I have already solve with this sintax that allow me to use the same function once.

[jQuery] Re: anonymous function and code reusing

2009-06-13 Thread MorningZ
I thought it should have worked but it doesn't You cannot pass params like that in a click event instead of $(document).ready(function(){ $(#moon).click(myFunction(param)); $(#earth).click(myFunction(param2)); function myFunction(param){ alert(param); } }); use

[jQuery] Re: anonymous function and code reusing

2009-06-13 Thread John Bill
it is very fun! why? 2009/6/14 MorningZ morni...@gmail.com I thought it should have worked but it doesn't You cannot pass params like that in a click event instead of $(document).ready(function(){ $(#moon).click(myFunction(param)); $(#earth).click(myFunction(param2)); function

[jQuery] Re: anonymous function and code reusing

2009-06-13 Thread MorningZ
What is that reply supposed to mean? On Jun 13, 9:48 pm, John Bill hexudon...@gmail.com wrote: it is very fun!  why? 2009/6/14 MorningZ morni...@gmail.com I thought it should have worked but it doesn't You cannot pass params like that in a click event instead of