A small question today: how do I get the return value of a JavaScript async function? 1. When the error attempt was not in the same year, my initial attempt: <script>function getsomething () {var r = 0; SetTimeout (function () {r = 2;}); return r;} function compute () {var x = getsomething (); alert (x * 2);} Compute (); </script>2. The callback function pops up not 4, and
1. How to get the return value of JavaScript async function
Summary: Today's study of a small problem: how to get the return value of the JavaScript async function? 1. When the error attempt was not in the same year, my initial attempt: <script>function getsomething () {var r = 0; SetTimeout (function () {r = 2;}); return r;} function compute () {var x = getsomething (); alert (x * 2);} Compute
2. Detailed introduction to JavaScript asynchronous function development code example
Summary: For most JavaScript developers, the async function is a novelty, and its development has gone through a long journey. Therefore, this paper attempts to summarize the development of JavaScript asynchronous function: In the near future, we can only write callback function to implement asynchronous, then promise/a+ the standard comes out, and then there is the generator function, and the next is obviously the async function. Now let's review the evolution of JavaScript async functions over the years. callback function callbacks It seems that everything should start with the callback function. Different.
3. Use the Bind () method in JavaScript to make the code cleaner and more detailed
Summary: A few weeks ago, I wrote an article about how to turn off the effect of calling asynchronous functions in a loop and how to deal with this problem. In my recent coding, I found a simpler approach. In this process, it eliminates the anonymous function and removes the linting error, "Do not write functions in the loop." You see, I've been using the bind () test in JavaScript. It turns out that we can use bind on multiple occasions, including the closure problem I mentioned a few weeks ago. What is bind ()? The BIND function was recently added to the JavaScript specification saying:
4. JavaScript Advanced Series-function declaration and expression
Summary: A function is a class object in JavaScript, which means that functions can be passed like other values. A common use is to pass an anonymous function as a callback function into an asynchronous function.
5. JavaScript Asynchronous Call Framework (Part 4-chained call) _javascript tips
Introduction: We have implemented a simple asynchronous calling framework, however, there are some drawback, that is, sequential execution of asynchronous functions need to be declared in a nested manner.
6. Nodejs File operation module FS (Files System) Common functions Concise summary _node.js
Introduction: This article mainly introduces the Nodejs file operation module FS (Files System) commonly used functions concise summary, the FS module of the majority of asynchronous functions are introduced, and in Chinese comments, which is convenient to use, the need for friends can refer to the next
7. JavaScript Learning notes function (i): function declaration and function Expression _ basic knowledge
Summary: function is the first class of objects in Javascript, which means that functions can be passed like other values. One of the most common uses is to pass an anonymous function as a callback function to another asynchronous function.
8. Use promise to encapsulate asynchronous functions in Nodejs _node.js
Introduction: This article mainly introduces the use of promise in Nodejs to encapsulate asynchronous functions, using a unified chain API to get rid of multiple callbacks nightmare, very practical small skills, I hope the small partners can like
9. Talk about the development process of JavaScript asynchronous function _javascript skills
Summary: For most JavaScript developers, the async function is still a novelty, and its development has gone through a long journey. This article will summarize the development of JavaScript asynchronous functions, and indicate that the future async function will become the main way to implement Asynchrony.
"Related question and answer recommendation":
Javascript-node.js how to get the return value of an asynchronous function callback.
JavaScript-How an asynchronous function calls n times
How does an asynchronous function with a callback function in a parameter typically be defined in c++11?
How and let async function take precedence in JAVASCRIPT-JS?
JavaScript-What is the order of asynchronous queue execution?