【发布时间】:2018-06-12 11:24:22
【问题描述】:
function Chat() {
// hander vent //
// this.message_text.on("keyup click", this.saveMessage);
$('.chat').on("click", this.init);
}
Chat.prototype.init = function() {
var sef = this;
this.hihi();
}
Chat.prototype.hihi = function() {
return 2;
}
let chat = new Chat();
我在类类型原型中定义了两个方法。 但是当我在函数 init 中调用函数名 hihi 时。 当我使用 Chat 类型的 create 实例运行代码时。 它无法运行并显示错误。
TypeError: this.hihi is not a function at HTMLButtonElement.Chat.init (fotozidiqo.js:9:10)
如何在初始化函数名中调用这个函数。
【问题讨论】:
-
this.init.bind(this)
标签: javascript function-prototypes