Created
March 29, 2014 17:34
-
-
Save evillemez/9858646 to your computer and use it in GitHub Desktop.
anonymous functions and stuff
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
var logSomething = function(something) { | |
console.log(something); | |
}; | |
function do_math(foo, bar, baz) { | |
return foo + bar + baz; | |
}; | |
function do_math_then(foo, bar, baz) { | |
var result = foo + bar; | |
baz(result); | |
}; | |
//this would actually return a value | |
var num1 = do_math(1, 2, 3); //num1 = 6 | |
//this won't return anything, it'll just execute the function you send it | |
//in this case - an anonymous function | |
do_math_then(1, 2, function(result) { | |
console.log(result); //will log "3" | |
}); | |
//same as above - but instead of an anonymous function defined inline, it's | |
//a reference to a function defined elsewhere | |
do_math_then(1, 2, logSomething); //will log "3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment