Yesterday a friend and I chatted to JS in the asynchronous and synchronous, and then from the asynchronous and synchronous problems to draw the other side of the function, feel very good, hereby share
====
Chase Dream: Chat is synchronous or asynchronous
Small A: Asynchronous
Little A: Talk to you and talk to someone else.
Chasing the dream son: that depends on how to talk,
Little a: Then you can't say I was wrong
Chase Dream Son: If you wait for another person to answer and then return, that is, you one sentence me, that is synchronized
Little a: But if I talk to you, my co-workers are talking to someone.
Small A: Is asynchronous
Chasing a dream: if you and the other side left a sentence, not in order, it is asynchronous
Chase Dream Son: I say you are wrong because, you say is asynchronous
Chasing the dream: not saying what the situation is asynchronous
Small A: Not to say that the left sentence is not in the right order is asynchronous
Small A: And it should be in the case of your input I can go to chat with others ah
Chasing the dream son: Yes, that's what it means.
Little a:??
Little A: I'm right.
Chasing the dream son: You are right, the left one sentence again this is too fan, not an asynchronous
Little A: Well
Chasing the dream: Async is not to wait
Small A: Yes
Small A: synchronization is sequential but will clog the asynchronous solution but will also change the order
Chasing the Dream: Change Order is the result of the results, do not focus on the order
Little a: Um, yes.
Chasing the dream: in the process of waiting, can do other things, is the nature of asynchrony, or the value of async
Small A: What do you have to say about the callback function?
Chasing a dream: To finish something, to inform you
Little a: And this thing has to be done in the end.
Chasing the dream son: that's not what it says
Chasing a dream: it doesn't have to be the last to execute this callback function
Little a: It's going to be done last.
Chasing a dream: The callback is, you tell someone beforehand, you say XX you do a thing to inform me, when he finished, will tell you, but he told you after you can do other
Chase Dream Son: So there is no last execution to say
Chasing the dream son: You say the last execution, then you have an example?
Little a: I'm looking for
Small A: You see this he has output this in advance .... Then execute the last callback output in the FN.
Little a:https://www.cnblogs.com/moltboy/archive/2013/04/24/3040213.html
Chase Dream Son: haha
Chasing the dream son: You look at the surface
Chasing a dream: The callback function has nothing to do before execution
Chase Dream: When do you want to execute when execution
Chasing dreams: It's up to you to decide.
Chasing a dream: Although seemingly the callback function is the last execution, but this is just its table like
Chasing the dream: You Ajax, the callback function can also be executed after the other AH
Chasing a dream: The callback function is a very simple thing, don't think it's complicated.
Small A: I can only look at the surface
Little A: I thought he was the last to do it.
Chasing the dream: Pass the function as a parameter into another function. This function is called a callback function.
Chasing the dream son: Just look at him write this sentence just fine
Small A: [Strong]
Chasing the dream son: the other is the surface
Small A: [Eye-eyed]
Chasing the dream: the surface of things, different people will be seen as different things
Chasing dreams: There will be misunderstandings
Little a: Okay.
Chase Dream Son: Often he just said a certain aspect, but you think it is everything
Chasing a dream: Just like a callback function
Chasing the dream son: you and I yesterday said the callback function, early on the road to think about the function of the
Little a: And then what?
Chasing the dream son: found that previously did not realize one thing, the function has a more important
Chasing dreams: That's the time to choose
Small A: Continue
Chasing dreams: If not, async is unlikely to happen.
Little a: Just a little bit of something I'm a little dizzy I still have to look more and think about it.
Small A: in-depth
Chase Dream Son: you want ah. The function is not up to you to decide when to execute
Small A: Of course, call it to execute the
Chasing a dream: If you don't have this, do you think async is possible?
Chasing the dream: Without this, all the code is executed directly, that is, only synchronized
Little a: But you just tell him when to execute and when he's done, you don't know, asynchronously.
Chase Dream Son: You don't understand my point
Little a: I know what you mean, we can control when he's going to do it. Asynchronous
Chasing the dream son: This is not right, the function is not equal to async, I mean the function is the basis of implementation of asynchrony, if there is no function can not be implemented asynchronously, but the function itself is not asynchronous, the nature of the asynchronous is through multi-threaded to achieve, or by waiting for the opportunity to delay execution to achieve the purpose, such as JS in the settimeout, so async is not equal to the function, and I say the function is to implement the basis of asynchrony is that if there is no function, and you want to do something again to execute a piece of code, then you think your code is either directly executed, Or wait until it's done, and then execute another piece of code, which is the synchronized
====
Always think that the function is a combination of code fragments, but now think of the function is not only the combination of code and reuse, another purpose is to choose the timing of execution, it is difficult to imagine that no function of JS will be what, I think it will be another language, another kind of grammar
Then I thought, I was chatting and said: "If you and the other side left a sentence, not in order, it is asynchronous" this sentence is not really wrong, just did not express clearly, if you and a two people chatting, you first asked a a question, but you did not wait a reply, but then asked a another question, that is asynchronous
JavaScript, functions are the basis for implementing Asynchrony