Because of the asynchronous relationship, the code may be written in a different order than the order of execution, and may want to execute a before B, but because async might be executed before a. For example, using afnetworking to request data in OC and then refresh the page, because the network request is a block-implemented asynchronous method, So there is no data at the time of the refresh, in order to solve this problem, it will usually refresh the page in block at the end of the request response (this will return to the problem of circular referencing, but it will not appear in node).
Above is a chained callback in an asynchronous execution in OC, which is also used in node. js to invoke a method in a callback to implement a chained callback.
function Logcar (car,callback) { Console.log ( "Saw a%s" ,car); Process.nexttick (callback);} function Logcars (cars) { var car=cars.pop (); if (Cars.length) {Logcar (car, function () {logcars (cars);; }); }} var cars = ["Ferrari", "Porsche", "Bugatti" "Lamborghini", "Aston Martin" ];logcars (Cars) ;
"C:\Program Files (x86) \jetbrains\webstorm 11.0.3\bin\runnerw.exe" with exit code 0
node. JS Self-study Phase summary:
Several blogs from the previous to the present are the basis of the syntax in node. js, which is the basis for later play. The following to learn the buffer, stream for the file module, Http, sockets, etc. lay the foundation, It's sort of gradual. Most of the behind are familiar with the interface of some applications, today see the next buffer, stream and file part, is the use of some of node. JS's API, understanding is not too difficult to understand, mainly in these days of some node. js model, The operation mechanism and JS object-oriented, callback comparison is not good understanding.
node. JS Chained callback