Created
February 13, 2009 05:22
-
-
Save bdotdub/63060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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