Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doubles2(x, cb)
- {
- console.log('running doubles 2', x);
- setTimeout(function() { cb(x * 2)}, 1)
- }
- var value = 1
- var index = 10;
- function callback(val) {
- if(index===0) {
- alert(val + val*2)
- } else {
- index--;
- return val + doubles2(val * 2, callback);
- }
- }
- doubles2(3, callback)
- Glenn,
- 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)
- 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
- first call to doubles2...
- It works just fine if just embeded the alert into the last call of the stack.
- Also I looked at your library, very cool. I started by searching for ZōZō :).
- Anyway, thank you for speaking with me,
- danderson
Add Comment
Please, Sign In to add comment