Created
January 5, 2017 05:33
-
-
Save bepitulaz/f1b9ac42247b18252c569ea4e94f56ba to your computer and use it in GitHub Desktop.
Callback vs Promise
This file contains 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
/** | |
Misalnya kita memiliki fungsi yang baru dapat dijalankan setelah ada nilai dari jQuery.get(), | |
jangan gunakan global variable seperti sebelumnya. Buatlah sebuah fungsi baru di luar asynchronous function | |
yang dapat dipanggil setelah jQuery.get() selesai. | |
*/ | |
jQuery.get('http://example.com/data.json', function(data) { | |
doSomething(data); // lempar data dari server ke dalam sebuah fungsi | |
}); | |
function doSomething(dataFromServer) { | |
// lakukan operasi sesuatu di sini. | |
console.log(dataFromServer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment