Javascript 无法读取setInterval中的属性

Javascript 无法读取setInterval中的属性,javascript,node.js,this,setinterval,Javascript,Node.js,This,Setinterval,在node.js上,我得到一个错误: TypeError: Cannot read property 'talk_duration' of undefined From:setTimeout(this.hangup,this.data.talk_duration*1000) 但是,在setInterval之外,我有console.log(this.data.talk\u duration)哪个工作正常 this.outcomeAnswer = function () { consol

在node.js上,我得到一个错误:

TypeError: Cannot read property 'talk_duration' of undefined
From:
setTimeout(this.hangup,this.data.talk_duration*1000)setInterval
中选择code>

但是,在
setInterval
之外,我有
console.log(this.data.talk\u duration)哪个工作正常

this.outcomeAnswer = function () {

    console.log(this.data.talk_duration); //this work

    num = 0;

    db.run("INSERT INTO in_queue (action_id, state) VALUES ('" + this.data.action_id + "', 'InQueue')", function (error) {
        queueCheckLoop = setInterval(function () {

            num++;

            if (num == 5) {
                clearInterval(queueCheckLoop);
            }

            db.each("SELECT count(*) as total FROM agent_queue WHERE state = 'Ready'", function (err, row) {
                if (row.total > 0) {
                    clearInterval(queueCheckLoop);
                    setTimeout(this.hangup, this.data.talk_duration * 1000);
                }
            });
        }, 1000);
    });
}

您需要记住
是OucomeResponse函数的最上面一行,例如:
var=this

然后使用
that.data.talk\u duration
在不同范围的函数中。

我怀疑
这个
不是你想象的那样。您现有的console.logs似乎证实了这一点。我们可以将此链接到一个规范问题。一定是的。不过这个问题有一个骗局。