Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
How to Prevent
Callback Hell
Tianyu ZHAO
Self-Introduction
From China
Joined Drecom 1 year ago
Rails Developer
What is callback hell?
Why should we deal with it?
Hard to Understand
How to avoid this?
Name your functions
Define new functions
Use Promise object
Use Promise object
Create custom getJSON function
Use Promise object
Use custom getJSON function
Use Promise object
Don’t have to do that at all (Deferred Object in jQuery 1.8+)
http://api.jquery.com/category/deferred-o...
Use Promise + Generator
What’s Generator?
Use Promise + Generator
More about Promise
Use Promise + Generator
More about Promise
Use Promise + Generator
Cool Library: co (https://github.com/tj/co)
yield Promise
Use Promise + Generator
Cool Library: co (https://github.com/tj/co)
Promise
resolver
resolver
Generator
.next()
Promise
re...
Conclusion
Callback hell is kind of the feature of JavaScript
Some people like it, some people don’t like it
Decide how to...
Thank you!
Upcoming SlideShare
Loading in …5
×

How to Prevent Callback Hell

913 views

Published on

Introduce some methods to prevent callback hell in JavaScript.

Published in: Technology
  • Be the first to comment

How to Prevent Callback Hell

  1. 1. How to Prevent Callback Hell Tianyu ZHAO
  2. 2. Self-Introduction From China Joined Drecom 1 year ago Rails Developer
  3. 3. What is callback hell?
  4. 4. Why should we deal with it? Hard to Understand
  5. 5. How to avoid this?
  6. 6. Name your functions
  7. 7. Define new functions
  8. 8. Use Promise object
  9. 9. Use Promise object Create custom getJSON function
  10. 10. Use Promise object Use custom getJSON function
  11. 11. Use Promise object Don’t have to do that at all (Deferred Object in jQuery 1.8+) http://api.jquery.com/category/deferred-object/
  12. 12. Use Promise + Generator What’s Generator?
  13. 13. Use Promise + Generator More about Promise
  14. 14. Use Promise + Generator More about Promise
  15. 15. Use Promise + Generator Cool Library: co (https://github.com/tj/co) yield Promise
  16. 16. Use Promise + Generator Cool Library: co (https://github.com/tj/co) Promise resolver resolver Generator .next() Promise resolver
  17. 17. Conclusion Callback hell is kind of the feature of JavaScript Some people like it, some people don’t like it Decide how to handle it by oneself (simply name functions or use Promise + Generator)
  18. 18. Thank you!

×