Created
October 21, 2016 03:45
-
-
Save josedigital/75a9ea4dd5a46302ada16ed5449196a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // how a promise works in javascript | |
| function doWorkPromise(data) { | |
| return new Promise(function(resolve, reject) { | |
| resolve('everything worked'); | |
| reject({ | |
| error: 'something bad happened' | |
| }); | |
| }); | |
| } | |
| // the following code is basically a function (called 'then') with 2 functions as args | |
| // function(data).then(func1() {}, func2() {}); | |
| doWorkPromise('some data').then(function(data) { | |
| console.log(data); | |
| }, function(error) { | |
| console.log(error); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment