daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function doubles2(x, cb)
  2. {
  3.     console.log('running doubles 2', x);
  4.     setTimeout(function() { cb(x * 2)}, 1)
  5. }
  6.  
  7.  
  8. var value = 1
  9. var index = 10;
  10. function callback(val) {
  11.     if(index===0) {
  12.       alert(val + val*2)
  13.     } else {
  14.       index--;
  15.       return val + doubles2(val * 2, callback);
  16.     }
  17. }
  18. doubles2(3, callback)
  19.  
  20. Glenn,
  21.  
  22. It was very cool talking to you. That last question was a bit tricky. I didn't realize the closure starts with the global scope. (Crazy how the v8 engine optimizes that)
  23. I also didn't realize that the alert along with the doubles 2 function will never alert the correct number because that value will never be returned from the
  24. first call to doubles2...
  25. It works just fine if just embeded the alert into the last call of the stack.
  26.  
  27. Also I looked at your library, very cool. I started by searching for ZōZō :).
  28.  
  29. Anyway, thank you for speaking with me,
  30.  
  31. danderson
RAW Paste Data
Top