一旦我使用 this 关键字遍历它,数组就为空

array is empty as soon as i loop over it using the this keyword

我有一个用对象填充的数组,当我使用 this 关键字遍历它时,我得到一个空数组,代码如下:

for(var i =0, j = this.data.length ; i < j ; i++) {
            var cur = this.date[i];
            var bubble = this.createBubble(width , this.year.min , cur.start , cur.end );

            /* Add data-duration once i have that figured it out */
            var line = [
                '<span style="margin-left: ' + bubble.getStartOffset() + 'px; width: ' 
                + bubble.getWidth() + 'px; " class="bubble bubble-' + (cur.type || 'default' ) +  '"></span>',
                '<span class="label">'+ cur.text +'<span>'           
            ].join('');

            html.push('<li>'+  line  +'</li>')  
        }

查看第二行 var cur = this.date[i]; ,如果我向这行代码添加断点,并且在控制台中,如果我这样做 this.data ,我会得到一个对象数组,但是当我将鼠标悬停在 this.data[i](在源选项卡中),data 似乎是空的,知道为什么吗?由于这个错误,我的脚本卡在了这里。

重现错误 您可以看到此错误 HERE ,转到 chrome 中的源选项卡并打开 reverse.js 并在第 29 行添加断点 ... 现在重新加载,你会看到我上面描述的。

所以重复我的问题,为什么 this.data[i] 是空的?这是否与 this 失去上下文有关,我不这么认为,但仍在询问?

你没看错吧? 你说 this.data[i],但在你的代码中我看到 var cur = this.date[i];