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
mode=javascript/javascript:text/javascript** | |
speed=1.5** | |
data=[{"change":{"origin":"+input","duration":5505,"text":["function CounterWidget(parentNode) {}"],"from":{"line":0,"ch":0},"to":{"line":0,"ch":36}},"time":1578914274375},{"change":{"origin":"+input","duration":0,"text":["\n"],"from":{"line":0,"ch":36},"to":{"line":0,"ch":36}},"time":1578914280349},{"change":{"origin":"+input","duration":0,"text":["\n"],"from":{"line":1,"ch":0},"to":{"line":1,"ch":0}},"time":1578914280477},{"change":{"origin":"+input","duration":6886,"text":["\tconst btn = document.createElement('button');\n"],"from":{"line":1,"ch":0},"to":{"line":1,"ch":46}},"time":1578914280899},{"change":{"origin":"+input","duration":0,"text":[" "],"from":{"line":2,"ch":0},"to":{"line":2,"ch":0}},"time":1578914287785},{"change":{"origin":"+input","duration":6870,"text":["const span = document.createElement('span');\n"],"from":{"line":2,"ch":4},"to":{"line":2,"ch":48}},"time":1578914288054},{"change":{"origin":"+input","duration":0,"text":[" "] |
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
// domeSomethingAsync is the first promise. | |
var result = doSomethingAsync() | |
// It has a `then` method for chaining | |
.then(...) | |
// result is a different Promise. It has its own then method | |
result.then(...) => returns another new Promise |
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
var promise = remoteDataCall(); | |
promise.then(function (result) {}); | |
promise.then(function (result) {}); | |
// Same result as above without executing `remoteDataCall` again. |
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
// The first call returns promise1 | |
remoteDataCall().then(function (result) {}); | |
// Second call returns another promise2 !== promise1 | |
remoteDataCall().then(function (result) {}); |
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 getSomeJSON(url, callback) { | |
// AJAX call to get data from server. Accepts callback and calls | |
// with callback(err, response) | |
... | |
} | |
function fetchJSON(url) { | |
var deferred = new Deferred(); | |
getSomeJSON(url, function (err, response) { | |
if (err) return deferred.reject(err); |
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 getSomeJSON(url, callback) { | |
// AJAX call to get data from server. Accepts callback and calls | |
// with callback(err, response) | |
... | |
} | |
function fetchJSON(url) { | |
return new Promise(function (resolve, reject) { | |
getSomeJSON(url, function (err, response) { | |
if (err) return reject(err); |
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 dadBranch() { | |
var dadStrategy = askDadForMoney() | |
.then(buyMangoes, sitAndCry); | |
return dadStrategy; | |
} | |
getMoneyFromAccount() | |
.then(buyMangoes, dadBranch) | |
.then(eatMangoes) |
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
getMoneyFromAccount() | |
// buyMangoes here will throw an Error | |
.then(buyMangoes, dadBranch) | |
// Next handler in chain | |
.then(eatMangoes, handleThief) | |
The `handleThief` function is called when buyMangoes throws an exception |
NewerOlder