So, promises are the big thing now in JavaScript and all that shit. Though they are a fairly old concept. In short using promises means you're giving up on your dependency on time and mutable state, and buying into dependency on your data, regardless of time, or structure, or any of those unnecessarily complicated things.
First, let's build a conceptual understanding of promises, and then I'll show how this maps to the particulars of the Promises/A+ specification. A promise is a placeholder for a value. Instead of saying what your value depends on through your program structure, i.e.: doX(a); doY(a); ...
you say what the value depends on through other values. ie.: b = doX(a); c = doX(b);
— here b
depends on a
; and c
depends on b
, which depends on a
.
Or, a more "visual" representation of this would be:
var a = Promise();
b = a.then(doX);