Home  >  Article  >  Web Front-end  >  Self-understanding and examples of JavaScript callback function concepts_javascript skills

Self-understanding and examples of JavaScript callback function concepts_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:30:01850browse

This article is suitable for entry-level JavaScript players to read, and experts can easily pass it.

Let’s talk some gossip first. In China, there is such a phenomenon: no matter what words or concepts, there will always be some people who explain these things in a magical way, seemingly making others feel that they are very powerful even if they don't understand. Actually, I don’t know how many there are. I personally prefer simplicity and clarity. No matter what words or concepts, if you can use a short sentence or two to make everyone understand, this is your skill. Okay, let’s stop chatting and get to the point.

What is Callback in JavaScript? In my words, method b is passed as a parameter to method a. When method a is executed, another specified function is executed (here is function b) ). Let’s look at an example:

Copy code The code is as follows:



Callback function test







Here main(b ), then b is called a callback function. Is it easy to understand? Then some people will ask why I can't put the call of b in the main function? It is indeed possible, but then your main method can only call b. Here we pass b to main, or a to main, then the callback method in main is a dynamic callback function. The advantage lies here.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn