Skip to content

Instantly share code, notes, and snippets.

@vnys
Created July 28, 2014 08:00
Show Gist options
  • Save vnys/372473fe38d96c3f06ce to your computer and use it in GitHub Desktop.
Save vnys/372473fe38d96c3f06ce to your computer and use it in GitHub Desktop.
promises experiment
var Promise = require('es6-promise').Promise;
function get(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
if (req.status === 200) {
resolve(req.response);
} else {
reject(Error(req.statusText));
}
}
req.onerror = function() {
reject(Error('Network error'))
}
})
}
get('file.json').then(function(){}, function(){});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment