![](/img/trans.png)
[英]What is the difference between JavaScript Engine and JavaScript Runtime Environment
[英]In javascript runtime, what is the difference between a “frame” of the stack and a “message” of the queue?
在本文中 ,我正在看这段代码:
function foo(b) {
var a = 10;
return a + b + 11;
}
function bar(x) {
var y = 3;
return foo(x * y);
}
console.log(bar(7)); //returns 42
在下一段中,他们说每个功能栏foo是添加到堆栈中的框架。
但是我不知道队列在哪里。 在那段代码中,console.log()的“消息”在哪里? 我们如何区分消息和堆栈框架?
您可以向函数添加一些输出,该函数在运行时实际上正在堆栈上运行。
每个函数调用都会创建一个新的堆栈条目,并且在返回函数之后/之后该条目会弹出。
为了更好地证明和获取console.log
,返回值在temp
被替换,并在显示消息后返回。
function foo(b) { console.log('put foo on stack'); var a = 10, temp temp = a + b + 11; console.log('pop foo from stack'); return temp; } function bar(x) { console.log('put bar on stack'); var y = 3, temp; temp = foo(x * y); console.log('pop bar from stack'); return temp; } console.log(bar(7)); //returns 42
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.