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

模块章节中的一个问题 #27

Closed
ghost opened this issue May 5, 2017 · 2 comments
Closed

模块章节中的一个问题 #27

ghost opened this issue May 5, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented May 5, 2017

https://github.com/ElemeFE/node-interview/blob/master/sections/module.md#%E6%A8%A1%E5%9D%97%E6%9C%BA%E5%88%B6

“热更新”部分说“这里留下一个简单的问题, 既然可以通过新的上下文来避免污染, 那么为什么 Node.js 不给每一个.js文件以独立的上下文来避免作用域被污染?”

这里的答案是独立的上下文不会防止作用域被污染吧,因为node的vm模块创建的独立上下文中是可以访问到独立变量吧?

@liuhao1025
Copy link

这个地方个人感觉是文字游戏啦,独立的上下文阻止的是对全局作用域的污染,按照文中的用语,应该是防止对Node默认的VM的污染。作用域的话应该是指模块的作用域,因为本来就是局部的,所以不需要独立的上下文也不会被污染。
不过还是希望作者出来确认下啦,我是有点没太明白这里想问的是啥 T_T

@Lellansin
Copy link
Contributor

可以当做脑筋急转弯。对其了解到不同深度的人会给出不同的想法。

Feel free to reopen.

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

No branches or pull requests

2 participants