Created
November 8, 2018 21:46
-
-
Save jessamynsmith/bb29c42ce855597cb55f70f8114c64aa to your computer and use it in GitHub Desktop.
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
function myAsyncFunction(url) { | |
return new Promise((resolve, reject) => { | |
const xhr = new XMLHttpRequest(); | |
xhr.open("GET", url); | |
xhr.onload = () => resolve(xhr.responseText); | |
xhr.onerror = () => reject(xhr.statusText); | |
xhr.send(); | |
}); | |
} | |
prom = myAsyncFunction('https://www.google.com'); | |
prom.then(function(res) {console.log(res)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment