Created
June 29, 2016 14:48
-
-
Save lipelopeslage/22da6e3985f0ed73f85f75244184c8c8 to your computer and use it in GitHub Desktop.
ES2015 Promise - Simple chaining example
This file contains hidden or 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
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