Created
January 5, 2017 04:39
-
-
Save bepitulaz/6d83ba9ed3971376b1c4f0bd049e9dcb 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
/** | |
Pemrogram berusaha menyimpan nilai dari callback ke dalam variabel | |
yang berada di luar scope callback. | |
*/ | |
var iniVariabelGlobal; | |
jQuery.get('http://example.com/data.json', function(data) { | |
iniVariabelGlobal = data; // pemrogram berusaha menyimpan data ke dalam global variable | |
}); | |
// Isi variabelnya sudah pasti `undefined` | |
// Karena baris di bawah ini dieksekusi sebelum jQuery.get() selesai. | |
console.log(iniVariabelGlobal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment