是否可以在对象声明中在 JavaScript 中声明变量?我正在寻找类似的东西
var myObject = {
myLabel: (var myVariable)
};
而不必写
var myVariable;
var myObject = {
myLabel: myVariable
};
编辑
我希望在 Node.JS 的上下文中这样做。这就是我所拥有的:
var server = {};
var database = {};
var moar = {};
module.exports = {
server: server,
database: databse,
moar: moar
};
doStuffAsync(function callback() {
// Populate variables
server = stuff();
database = stuff2();
});