-
-
Save azamsharp/bd8717de4695b5cccc4c9a977b8c1794 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
// CALLBACKS | |
// Functions that can be called back later | |
// Examples | |
// setInterval | |
function getMovies(moviesDownloaded) { | |
let request = new XMLHttpRequest() | |
request.onload = function() { | |
let response = JSON.parse(this.responseText) | |
// response.Search contains the movies | |
let movies = response.Search | |
moviesDownloaded(movies) | |
} | |
request.open("GET","http://www.omdbapi.com/?s=batman&apikey=564727fa") | |
request.send() | |
//return movies | |
} | |
getMovies(function(movies) { | |
console.log(movies) | |
}) | |
/* | |
function getCounter(counterUpdated) { | |
let counter = 0 | |
setInterval(function(){ | |
counter++ | |
// call a function with a updated value | |
counterUpdated(counter) | |
},1000) | |
//n counter | |
} | |
function displayCounter() { | |
console.log("display Counter") | |
} | |
getCounter(function(ctr) { | |
console.log(ctr) | |
}) // how do I get the counter value | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment