在nodejs中,有没有办法可以做到这一点?
//require something here and inject in this module
//all the properties visible in that module ex:
require("color");
//inject directly making properties from 'color' module global to this module.
console.log(red);
//'red' variable here came from 'color' module
我不知道这是否已经正确或我遗失了什么。
答案 0 :(得分:0)
我认为你必须明确设置你想要“导入”的每个值:
var color = require("color");
var red = color.red,
green = color.green;
// …
此外,您可以使用with
,但广泛不推荐:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with