2

後で呼び出すことができる方法で値を定義するのに問題があります。

最初に検索を定義すると、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 に答える