Does Node.js require inheritance?

前端 未结 3 1451
刺人心
刺人心 2021-01-04 14:12

In my server.js file I included the Underscore.js library.

var _ = require(\'underscore\')

I have my routes like this:



        
3条回答
  •  [愿得一人]
    2021-01-04 14:20

    As far as I know Node.js engine "requires/charges" a module/file.js in a different scope (I don't know exactly how), for security reasons (imagine a module could change the variables were it's required. That would be dangerous! More information about this concern: Information hiding).

    The only exception are global Node.js objects that are exposed into the module scope.

    A global object is, precisely the object "global", and everything you define without var keyword actually is added to that global object:

    foo_var = "Whatever"
    

    means that:

    console.log(global.foo_var) // Logs "Whatever"
    

提交回复
热议问题