课程: Mastering Web Developer Interview Code

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

What is the relationship between promises and callbacks?

What is the relationship between promises and callbacks?

课程: Mastering Web Developer Interview Code

What is the relationship between promises and callbacks?

- [Instructor] Promises are objects in JavaScript that describe what is supposed to happen when a time based operation takes place. They supplement callbacks and provide structure, and certain guarantees that help make asynchronous code a little more dependable and easy to use. First, let's take a look at what a callback is. A callback is nothing more than a function passed as an argument. So this part right here is what we would refer to as a callback. In this case, we're calling a function, the function has no name. So it's actually an anonymous function, we could just as easily call another function that we've created somewhere else. Callbacks are common on asynchronous events, the callback will be executed when something happens in this case, whenever a click event takes place. Now there are a few problems with callbacks. The most notable is that callback code often suffers from clarity. More importantly, callbacks…

内容