Request: Demo of a Javascript Promise?

I've tried to experiment a little with Javascript promises, but have
come to the conclusion that I still don't understand them.

I wonder if someone has a simple demo I can look at?
What I would want is a Web page that has:

- A function that returns a promise and installs success and failure
callbacks on it.
- A button that says "resolve" - when I push it, the promise's success
function is called, and the promise is resolved.
- A button that says "cancel" - when I push it, the promise's failure
function is called, and the promise is rejected.

I tried to write something like that, but my failure to achieve what I
wanted indicates that there's still something I don't understand.

        Harald

Received on Thursday, 26 February 2015 09:05:20 UTC