javascript - this.hasErrors 不是一个函数

标签 javascript function typescript

我在网上搜索了我的问题的解决方案,但找不到任何合适的答案。尽管网上有大量这个特定的问题。

在我的 typescript 文件中,我有以下三种方法:

hasErrors() {
    // Checking for errors
}

saveItem() {
    if (this.hasErrors())
        return;
    // Save item
}

sendItemToAuthority() {
    if (this.hasErrors())
        return;
    // Send item to authority
}

不知何故,sendItemToAuthority() 内的 this.hasErrors() 不被识别为函数,但在 saveItem() 中它无需任何问题。我在 Chrome 开发者工具中收到以下错误:

this.hasErrors is not a function

我发现以下可能性对我来说也不起作用(相同的错误消息):

sendItemToAuthority() {
    var self = this;
    if (self.hasErrors)
        return;
    // Send item to authority
}

有人可以引导我找到解决方案吗?我真的不明白为什么它不起作用。

最佳答案

saveItem() it works without any problem. I get the following error in chrome developer tools this.hasErrors is not a function

您很可能弄错了这个。使用箭头函数:https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html

关于javascript - this.hasErrors 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36349258/

相关文章:

javascript - 对 API 网关的 XMLHttpRequest 不起作用

javascript - 行内 block 删除底部空间以添加文本

c++ - 如何错误处理命令行参数?

c++ - 在 vector 使用中找不到 fatal error

css - 使用 Angular 2 快速设置 html 样式的方法

javascript - DZI Openseadragon和三个js球形图像

javascript - 以无冲突的方式将 Bootstrap Accordion 添加到具有旧版本 jQuery 的网站

c - 树递归编译,但在执行时崩溃

angular - 用尽 RxJs retryWhen 运算符尝试后如何抛出异常?

javascript - Multiple Item 轮播(JS转TS文件)