为什么对象无法读取自身?

时间:2019-08-28 08:30:25

标签: javascript object

我有这段代码,我正在尝试使用'_currentModel'对象访问'model'数组。

// an array I want to access
var model = [
    {
        name:'haha',
        image:'cat1.jpg',
        count: 0
    },
    {
        name: 'pew',
        image: 'cat2.jpg',
        count: 0
    },
    {
        name: 'wow',
        image: 'cat3.jpg',
        count: 0
    }
];

应该访问它的对象

var _currentModel = {
    index: 0,
    name: model[this.index].name, //error: model[this.index] is undefined
    image: model[_currentModel.index].image, //error: _currentModel is undefined
    count: model[_currentModel.index].count //error: _currentModel is undefined

}

0 个答案:

没有答案