Guest User

Untitled

a guest
Oct 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function foo(state) {
  2. function bar() { return 1; }
  3. return state ? bar : null;
  4. }
  5. foo(false) // null (bar is created but not used)
  6. foo(true)() // 1 (bar is created and returned)
  7.  
  8. function foo(state) {
  9. return state ? function() { return 1; } : null;
  10. }
  11. foo(false) // null (the anonymous function isn't even created)
  12. foo(true)() // 1 (the anonymous function is created and returned)
Add Comment
Please, Sign In to add comment