【发布时间】:2015-03-25 14:26:28
【问题描述】:
我有以下代码:
context
.on( 'hangup', this.handleHangup );
在类构造函数中
PlayMessage.prototype.handleHangup = function() {
log.callout.info( "Call [%s]: Client hungup.", this.row.get( 'id' ) );
this.endCall(); // Get out of here
}
作为类的函数。该类称为 PlayMessage。
我收到一条错误消息:
events.js:130 throw TypeError('监听器必须是函数');
谈论我在上面粘贴的 context.on( ... ) 行。
我应该如何使用类函数作为监听器?
【问题讨论】:
-
调用
context.on( 'hangup', this.handleHangup );时this关键字的值是多少? -
如果您在调试 node.js 代码时遇到问题,请查看https://nodejs.org/api/debugger.html#debugger_debugger。
标签: javascript node.js class listener dom-events