Node.js global variables

前端 未结 6 1418
耶瑟儿~
耶瑟儿~ 2020-11-22 13:06

I asked here: Does Node.js require inheritance?

And I was told that I can set variables to the global scope by leaving out the variable.

This does not

6条回答
  •  死守一世寂寞
    2020-11-22 13:24

    You can just use the global object.

    var X = ['a', 'b', 'c'];
    global.x = X;
    
    console.log(x);
    //['a', 'b', 'c']
    

提交回复
热议问题