Skip to content

Instantly share code, notes, and snippets.

@bdotdub
Created February 13, 2009 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdotdub/63060 to your computer and use it in GitHub Desktop.
Save bdotdub/63060 to your computer and use it in GitHub Desktop.
function click(theFunction) {
// Something happens
theFunction(event);
}
// Example 1
$('a').click(alert('hi'));
// Example 2: this does the same thing as example 1
alert_result = alert('hi');
$('a').click(alert_result);
// Example 3: this is essentially what examples 1 and 2 would be doing
alert_result(event);
/////////////////////////////////////////
// Example 4: this will work
$('a').click(function() { alert('hi') });
// Example 5: same as example 4
alert_function = function() { alert('hi') };
$('a').click(alert_function);
// Example 6: same as examples 4 and 5
alert_function(event);
/////////////////////////////////////////
// Essentially, when you call alert('hi'), you've already called the
// function. It can't do the alert if it has been already called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment