简体   繁体   English

查询JavaScript和Python的执行环境

[英]Query on Execution environment of JavaScript & Python

Below diagram is retrieved after running JavaScript code(top-half) on link1 and python code(bottom-half) on link2 下图是在link1上运行JavaScript代码(上半部分)并在link2上运行python代码(下半部分)后检索的

在此处输入图片说明

My question: 我的问题:

I see that names foo & bar are already sitting in global frame(in blue) of JavaScript Execution environment(EE) unlike python's EE? 我看到foobar名称已经坐在JavaScript执行环境(EE)的全局框架中(蓝色),这与python的EE不同吗? How did JavaScript interpreter know about these two names before starting interpretation? 开始解释之前,JavaScript解释器如何知道这两个名称?

How did JavaScript interpreter know about these two names before starting interpretation? 开始解释之前,JavaScript解释器如何知道这两个名称?

That's something called hoisting . 那就是所谓的吊装 Before the engine executes any line of code (of a function), it looks for all variable and function declarations and creates a binding in the current environment ( §10.5, steps 5 and 8 ). 在引擎执行(函数的)任何代码行之前,它会查找所有变量和函数声明,并在当前环境中创建绑定(第10.5节,步骤5和8 )。 In case of variable declarations, the value is undefined because the assignment has not taken place yet. 对于变量声明,该值是undefined因为尚未进行赋值。

Apparently Python doesn't work that way, but I'm not familiar enough with its inner workings to give an authoritative answer about that. 显然, Python无法以这种方式工作,但是我对其内部运作方式还不够熟悉,无法给出有关此问题的权威性答案。

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

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