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
感谢,明白了
P
大概意思是在node中你定义的全局变量其实非全局变量,它依托于所在的module。
就好比所在的module是个命名空间,这个变量从属于它
B
应该是说浏览器中文件里最外层的var定义是成全局的,即别的文件也能直接访问它 但在node中不一样,文件里最外层的var定义只有文件内部可以访问到它,如果要别的文件也能访问,则需要用exports
参与回复
登录后即可参与回复。登录