I hereby claim:
- I am jpina on github.
- I am jpina (https://keybase.io/jpina) on keybase.
- I have a public key ASDkCQurr4F2S8brFVZ5iTkJJD0J1ExG5S0dDMSdpw92fgo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
var promise = new Promise(function(resolve, reject) { | |
// do a thing, possibly async, then… | |
if (/* everything turned out fine */) { | |
resolve("Stuff worked!"); | |
} | |
else { | |
reject(Error("It broke")); | |
} | |
}); |
promise.then(function(result) { | |
console.log(result); // "Stuff worked!" | |
}, function(err) { | |
console.log(err); // Error: "It broke" | |
}); |
function get(url) { | |
// Return a new promise. | |
return new Promise(function(resolve, reject) { | |
// Do the usual XHR stuff | |
var req = new XMLHttpRequest(); | |
req.open('GET', url); | |
req.onload = function() { | |
// This is called even on 404 etc | |
// so check the status |