Skip to content

Instantly share code, notes, and snippets.

@lipelopeslage
Created June 29, 2016 14:48
Show Gist options
  • Save lipelopeslage/22da6e3985f0ed73f85f75244184c8c8 to your computer and use it in GitHub Desktop.
Save lipelopeslage/22da6e3985f0ed73f85f75244184c8c8 to your computer and use it in GitHub Desktop.
ES2015 Promise - Simple chaining example
var ajax = (str)=>{
return new Promise(function(resolve, reject){
$.get(str).success(resolve).fail(reject);
})
};
ajax('https://httpbin.org/get').then(function(res){
// primeiro then fitra valor
return res.url;
}).then(function(res){
// segundo then mostra o valor filtrado
console.log(res);
}).catch(function(err){
console.log(err);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment