Category: promises
-
JavaScript How To Convert Recursive Function With Callbacks to Use Promises
I updated one of my websites to use JavaScript promises instead of callbacks. It was pretty straightforward, but got a little tricky for a recursive function. Below is how to do the conversion update: Recursive callback function: function doSomething(value) { function callback(result) { console.log(‘Done ‘ + result); …
-
JavaScript How to Convert Callback to Promise
I finally finished upgrading my travel website to use Promises instead of callbacks. It was fairly straightforward. This is an example of the callback: function hasacallback(param1, callbackFunction) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { callbackFunction(this.responseText); …