Skip to content

Instantly share code, notes, and snippets.

@evillemez
Created March 29, 2014 17:34
Show Gist options
  • Save evillemez/9858646 to your computer and use it in GitHub Desktop.
Save evillemez/9858646 to your computer and use it in GitHub Desktop.
anonymous functions and stuff
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