On Oct 27, 5:10 pm, bytespider <r...@bytespider.eu> wrote:
> I've been thibking about promises in javascript, and whilst I think I
> understand the basics i fail to see how they are useful over the usual
> callback mechanisim.

Besides what was already mentioned, they have what I see as another
major benefit.  Instead of accepting various callback parameters, I
can write functions that return a very simple interface and leave it
to the caller to figure out what to do with the response.  Since the
code for the calling function is no more difficult, and often simpler,
this is a great win.  It's the difference between

    /**
     * function which does something
     * @param inputData
     * @param success callback.  Should accept `responseData`
parameter
     * @param failure callback.  Should accept `error` parameter
     * @return void
     */

and

    /**
     * function which does something
     * @param inputData
     * @return promise object which will resolve with `responseData`
or reject with `error`
     */

To me, this make implementing asynchronous behavior significantly
easier.

  -- Scott

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to