CNode

这段来自api的话没看懂,求解释

Cceclinux发布于12 年前最后回复12 年前3 回复4333 浏览0 收藏

In browsers, the top-level scope is the global scope. That means that in browsers if you're in the global scope var something will define a global variable. In Node this is different. The top-level scope is not the global scope; var something inside a Node module will be local to that module.

查看回复

回复 (3)

C
ceclinux#1·12 年前

感谢,明白了

P
peiweippww#2·12 年前

大概意思是在node中你定义的全局变量其实非全局变量,它依托于所在的module。

就好比所在的module是个命名空间,这个变量从属于它

B
blacktea#3·12 年前

应该是说浏览器中文件里最外层的var定义是成全局的,即别的文件也能直接访问它 但在node中不一样,文件里最外层的var定义只有文件内部可以访问到它,如果要别的文件也能访问,则需要用exports

参与回复
登录后即可参与回复。登录