我在网上搜索了解决问题的方法,但是找不到任何合适的答案。尽管在线上有很多这样的特定问题。
在我的打字稿文件中,我有以下三种方法:
hasErrors() {
// Checking for errors
}
saveItem() {
if (this.hasErrors())
return;
// Save item
}
sendItemToAuthority() {
if (this.hasErrors())
return;
// Send item to authority
}
this.hasErrors()
内部不知何故sendItemToAuthority()
不能被认为是一个功能,但在saveItem()
其中却可以正常工作。我在chrome开发人员工具中收到以下错误:
this.hasErrors不是一个函数
我发现以下可能性对我也不起作用(相同的错误消息):
sendItemToAuthority() {
var self = this;
if (self.hasErrors)
return;
// Send item to authority
}
谁能引导我找到解决方案?我真的不明白为什么它不起作用。
我终于找到了解决方案。在我的构造函数中,我有
this.saveItem = this.saveItem.bind(this);
但是忘了加
this.sendItemToAuthority = this.sendItemToAuthority.bind(this);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句