简体   繁体   English

javascript 是否为每个函数创建一个执行上下文?

[英]Does javascript creates a execution context for every function?

I am watching a course where the professor mentions a local execution context being created every time we execute a function created by ourselves (he does not says exactly that, however he does not mentions this when he explains external functions like setTimeOut or fetch ).我正在看一门课程,教授提到每次我们执行自己创建的函数时都会创建一个本地执行上下文(他没有确切地说,但是他在解释setTimeOutfetch等外部函数时没有提到这一点)。 However what happens when we call an external function (like setTimeOut or fetch ) does javascript creates a local execution context for this functions too?但是,当我们调用外部函数(如setTimeOutfetch )时会发生什么,javascript 是否也为该函数创建了本地执行上下文? What I mean by external functions is functions not created by ourself but part of an API.我所说的外部函数指的不是我们自己创建的函数,而是 API 的一部分。

Most external functions for javascript are actually written in C, so they don't have a javascript execution context per se. javascript 的大多数外部函数实际上是用 C 编写的,因此它们本身没有 javascript 执行上下文。 However, they still have a stack frame , which is similar to what a javascript execution context is.但是,它们仍然有一个 stack frame ,类似于 javascript 执行上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM