在node.js javascript中,为什么可以';我不能添加到子函数吗?
为什么这会失败,但是在node.js javascript中,为什么可以';我不能添加到子函数吗?,javascript,node.js,Javascript,Node.js,为什么这会失败,但是 game_state = function(){ this.players = function() { this.x = 0; }; } game_state.players['test'] = 1; 不是吗 我正在node.js中尝试,以防不清楚。感谢您的帮助。游戏状态是一个(构造函数)函数。函数的实例有一个players属性,但函数本身没有。我想你可能想要: game_state['test'] = 1; 编辑:这同样适用于内部函
game_state = function(){
this.players = function() {
this.x = 0;
};
}
game_state.players['test'] = 1;
不是吗
我正在node.js中尝试,以防不清楚。感谢您的帮助。游戏状态是一个(构造函数)函数。函数的实例有一个players属性,但函数本身没有。我想你可能想要:
game_state['test'] = 1;
编辑:这同样适用于内部函数。此外,在这两种情况下,您可能都可以使用对象文字。ahh。。。现在很明显;)非常感谢。
game_state = new (function()
{
this.players = new (function()
{
this.x = 0;
})();
})();
game_state.players['test'] = 1;