JSFoo 2012

It’s like kung fu with JavaScript and objects! All about building full size apps in JavaScript.

Escape from Callback Hell with Deferreds

Submitted by Yuvi Panda (@yuvipanda) on Aug 19, 2012

Section: Zen of JavaScript Technical level: Intermediate Session type: Tutorial Status: Confirmed & scheduled

Abstract

  • To explain fundamentals of deferreds, using jQuery's implementation for demonstration
  • Show how hard-to-understand callback based code can be converted to clearer Deferreds based code

Outline

Tired of writing JS with so many nested callbacks that it looks like the Gaza Pyramid turned sideways? Thought you'll never have to write synchronization code again but suddenly find yourself wanting to wait on 5 callbacks to return before you want to execute something? Hate having to add ugly boilerplate everywhere if you ever want to chain callbacks? Miss the return statement? Think your code looks ugly because it has way too many levels of indentation?

Start using Deferreds and fix all these! Deferreds are a way of managing callbacks that is painless, elegant and powerful. Using deferreds makes your code cleaner, easier to understand and less error prone. And free ponies too!

Requirements

Intermediate level of Javascript knowledge would be sufficient.

Speaker bio

Yuvi Panda is a 21 year old open source geek who chases shiny new things way too often. He wrote major parts of the Wikipedia Android/iOS app (JS/Phonegap), and the upcoming Wiki Loves Monument app (also JS/PhoneGap). He was yearning for a threaded model in Javascript until he found Deferreds. Amongst his hobbies is screaming 'USE DEFERREDS!' at anyone claiming to use Javascript. He's currently a student at KCG College of Technology.

Links

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('You need to be a participant to comment.') }}

{{ formTitle }}
{{ gettext('Post a comment...') }}
{{ gettext('New comment') }}

{{ errorMsg }}