Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用堆栈 #7

Open
Genluo opened this issue Aug 31, 2019 · 1 comment
Open

调用堆栈 #7

Genluo opened this issue Aug 31, 2019 · 1 comment

Comments

@Genluo
Copy link
Owner

Genluo commented Aug 31, 2019

调用堆栈定义

堆:内存分配,js引用类型的值是分配在堆内存中的

栈:当函数运行的时候将会把函数推进push到调用栈中去,结束的时候就会把栈顶元素移除。浏览器存在最大调用栈,当超过的时候将会报错。

调用栈和内存堆栈的区别

那么左边的head存在什么用处,平常我们听到的就是基本类型存放在栈中,引用类型存放在堆中,但是这些到底和head是不是有一定的联系呐?调用栈和内存堆栈的区别?

问题:

  • 为什么不能通过try catch捕获回调函数抛出出的错误?
  • 栈中存在着什么?
    里面存放的是上下文,分为两种上下文,一种是全局上下文,另一种是函数上下文
@wildfrontend
Copy link

wildfrontend commented Oct 4, 2020

好像不建議用
try catch 做設計,好像是因為 memory會lock住,所以catch 還要在補清除catch的寫法。

大概是這樣的解釋吧。
https://docs.microsoft.com/zh-tw/cpp/mfc/exceptions-freeing-objects-in-exceptions?view=vs-2019

當初我也會用 try catch 取代 promise
因為結構比較簡潔但後來就沒做這樣的堅持了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants