Guest User

Untitled

a guest
Jun 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // Function definition and invocation
  2. function speak(string) {
  3. console.log(string);
  4. }
  5. speak("Hello"); // logs "Hello"
  6.  
  7. // Store in a variable
  8. var talk = speak;
  9. talk("Hi"); // logs "Hi"
  10.  
  11. // Pass as an argument to a function
  12. // Return from a function
  13. function functionReturner(fn) {
  14. return fn;
  15. }
  16. var chat = functionReturner(talk);
  17. chat("Good Morning"); // logs "Good Morning"
  18.  
  19. // Store in a data structure
  20. var myFuncs = [talk];
  21. myFuncs[0]("Good Afternoon"); // logs "Good Afternoon"
  22.  
  23. // Owns properties
  24. talk.myProperty = "bananas";
  25. console.log(talk.myProperty); // logs "bananas"
Add Comment
Please, Sign In to add comment