Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created April 29, 2020 14:55
Show Gist options
  • Save azamsharp/bd8717de4695b5cccc4c9a977b8c1794 to your computer and use it in GitHub Desktop.
Save azamsharp/bd8717de4695b5cccc4c9a977b8c1794 to your computer and use it in GitHub Desktop.
// 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