Created
January 9, 2017 03:57
-
-
Save bepitulaz/de2adb2bfb243af76efcf82b7eea9157 to your computer and use it in GitHub Desktop.
Memahami Promise pada JavaScript
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
| var samplePromise = new Promise(function(resolve, reject) { | |
| // setTimeout untuk mensimulasikan async function | |
| setTimeout(function() { | |
| // Dapat diisi apapun. Yang paling umum menggunakan object Error | |
| reject(Error('Sengaja dibuat salah.')); | |
| }, 5); | |
| }); | |
| samplePromise.then(function(data) { | |
| console.log(data); // tidak terpanggil | |
| }).catch(function(error) { | |
| console.log(error); // isinya object Error | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment