In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how the function call stack works in JavaScript. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Dealing with stack information properly allows you to clean up useless data and focus on useful data. At the same time, a better understanding of Errors objects and their related properties can help you make better use of Errors.
How does the call stack work?
Before you talk about errors, you need to understand how the call stack works:
When a function is called, it is pushed to the top of the stack, and when the function is finished, it is removed from the top of the stack.
The data structure of the stack is LIFO, known as LIFO (last in, first out).
For example:
Function c () {console.log ('c');} function b () {console.log ('b'); c ();} function a () {console.log ('a'); b ();} a ()
In the above example, when function a runs, it is added to the top of the stack. Then, when function b is called inside function a, function b is pushed to the top of the stack. Function c is also pushed to the top of the stack when called inside function b.
When function c runs, the stack contains a, b, and c (in this order).
When function c is finished, it is removed from the top of the stack, and then the control flow of the function call returns to function b. After function b is run, it is also removed from the top of the stack, and then the control flow of the function call goes back to function a. *, and function an is also removed from the top of the stack after running.
To better demonstrate stack behavior in demo, you can use console.trace () to output the current stack data in the console. At the same time, you should read the output stack data from top to bottom.
Function c () {console.log ('c'); console.trace ();} function b () {console.log ('b'); c ();} function a () {console.log ('a'); b ();} a ()
Running the above code in Node's REPL mode results in the following output:
Traceat c (repl:3:9) at b (repl:3:1) at a (repl:3:1) at repl:1:1 / /
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.