Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created June 24, 2018 17:56
Show Gist options
  • Select an option

  • Save sevperez/06c02d783d382fe2a43559482a5e9d03 to your computer and use it in GitHub Desktop.

Select an option

Save sevperez/06c02d783d382fe2a43559482a5e9d03 to your computer and use it in GitHub Desktop.
// Function definition and invocation
function speak(string) {
console.log(string);
}
speak("Hello"); // logs "Hello"
// Store in a variable
var talk = speak;
talk("Hi"); // logs "Hi"
// Pass as an argument to a function
// Return from a function
function functionReturner(fn) {
return fn;
}
var chat = functionReturner(talk);
chat("Good Morning"); // logs "Good Morning"
// Store in a data structure
var myFuncs = [talk];
myFuncs[0]("Good Afternoon"); // logs "Good Afternoon"
// Owns properties
talk.myProperty = "bananas";
console.log(talk.myProperty); // logs "bananas"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment