Does node.js have equivalent to window object in browser

前端 未结 2 503
自闭症患者
自闭症患者 2020-11-28 11:15

What I mean is does node.js have object that are global function methods of. Like this in browser:

function myGlobalFunction() {
    console.log(this === win         


        
2条回答
  •  一生所求
    2020-11-28 11:25

    Yes, the global variable is the global object in Node.js

    From the docs:

    global# {Object} The global namespace object. 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.

提交回复
热议问题