From the course: JavaScript: Async

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Building asynchronous code with promises

Building asynchronous code with promises - JavaScript Tutorial

From the course: JavaScript: Async

Building asynchronous code with promises

- Modern JavaScript includes a method called Fetch, that creates an asynchronous HTTP request using a syntax that's based on Promises. However, to get practice building Promises from the ground up, we're going to create our own method using the Promises constructor to create and send an XHR request for the weather information on the explore California site. So we're going to start by basically rewriting the GET Method that we've already created. So our GET Method is just creating an XHR request, sending that and then working with the response, and we just want to turn this into code that is actually creating and then working with a Promise. So the first thing I'm going to do is take out the success and fail Callback parameters because Promises don't actually work with those. We don't use Callbacks with Promises, We do that more Under the Hood. And then the first line of my function, I want to return a new Promise, and this…

Contents