【发布时间】:2018-05-05 03:08:45
【问题描述】:
我遇到了一个 addListener 事件。在收到一条我想调用的消息时,然后在我的代码中调用一个函数,但得到函数未找到错误。
ERROR TypeError: this.plotBus 不是函数
一个非常简单的例子。
this.pubnub.publish({
channel: 'test',
message:["hello"]
})
this.pubnub.addListener({
message: function(msg) {
console.log(msg);
this.plotBus(msg)
}
})
this.pubnub.subscribe({
channels: ['test'],
triggerEvents: ['message']
});
plotBus(bus){
console.log("Plotting Bus with received data")
}
【问题讨论】:
-
你需要把你的plotBus函数放在最上面。