2

我无法以以后可以调用它们的方式定义值。

如果我先定义 Search,则 Search.commands[3] 未定义。如果我先定义 commandList,则 commandList.commands[0] 未定义。

有没有更好的方法来定义这些对象,以便顺序无关紧要?

var Search = {
    'str': 'search',
    'param': 'search',
    'action': '',
    'commands': [
        Category,
        Location,
        Sort,
        commandList
    ]
}

var commandList = {
'commands': [
    Search,
    Category,
    Stop
]
}
4

2 回答 2

4
var Search = {
    'str': 'search',
    'param': 'search',
    'action': ''
};
var commandList = {
    'commands': [
        Search,
        Category,
        Stop
    ]
};
Search.commands = [
    Category,
    Location,
    Sort,
    commandList
];
于 2013-01-31T00:01:14.777 回答
1

你可以使用这样的东西:

var Search = {
    'str': 'search',
    'param': 'search',
    'action': ''
};

var commandList = {
};



Search.commands = [
        Category,
        Location,
        Sort,
        commandList
    ];

commandList.commands = [
    Search,
    Category,
    Stop
];
于 2013-01-30T23:59:53.687 回答