码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Call Stack

时间:2016-01-26 21:34:37      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

Every time when a function run it will be push into the call stack and put on the top,  you can think call stack is something like a heap... Javascirpt has only one call stack. 

技术分享

 

In the picture, main() get call first, so put into the call stack;

second, printSquare(), put into the call stack;

third, inside printSquare() call suqare() function, so put into call stack;

fourth, inside square() function, multiply() function get call....

 

--------------------------

 

When function return or done, the function will be poped up from the call stack:

技术分享

So, multiply() function ruturned, so pop up from the call stack;

then square();

then inside printSquare() function, console.log() funciton get call, so need to push intot the call stack.

After that, console.log() pop up;

printSquare() pop up;

finally main() pop up;

 

You can see the call stack from the Chrome dev tool‘s source tab when you use ‘debugger‘.

 

[Javascript] Call Stack

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5161558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!