跳到主要内容
CNode

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

社区
Cceclinux发布于 13 年前最后回复 13 年前
343580

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#313 年前

感谢,明白了

B
blacktea#213 年前

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

P
peiweippww#113 年前

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

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

参与回复

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