下面是一个包含对象的函数,我希望能够使用参数访问对象内的特定主体,即使用索引。
问题是,当我尝试以这种方式访问属性时,我得到
不明确的
当控制台记录它时。我究竟做错了什么?
moveLeftBtn.on('click', function(nr){
    var theBody = {
        bodies: {
            a: 'foo1',
            b: 'foo2',
            c: 'foo3'
        }
    };
    var newBody = theBody.bodies[1];    // temporarily hardcoded value instead of argument
    console.log(newBody);    // <-- undefined, why?
    return newBody;
});
编辑
如果我控制台日志theBody.bodies,我可以看到它的值(Object {a: Array[5], b: Array[5], c: Array[5]}),但是当我尝试访问它的属性时,[1]我得到
不明确的
(即使属性包含字符串)。