课程: JavaScript: Patterns

今天就学习课程吧!

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

What is a callback and its role?

What is a callback and its role? - JavaScript教程

课程: JavaScript: Patterns

What is a callback and its role?

- [Instructor] Another term that you may have heard many times and not quite sure what it means is the callback. What is a callback and its role? In its simplest terms, a callback function is a function that is called inside of another function. In other words, whenever you pass a function in the arguments and run it inside the function, you're doing the callback pattern. Let me demonstrate. So we're back into Visual Studio Code in the index.js and what we're going to do is keep the calc function. And I'm simply going to change the return to four times four so we have a different number. And then what we're going to do is remove these two here and I'm going to create another function, like I said, we need to create a new function that we're going to call printCalc. And we're going to pass as the callback the argument callback. And it's going to make sense to you in a couple of seconds, so let's continue. And then let's…

内容