【问题标题】:TypeError: Undefined is not a function. iOS Safari Evaluating function. CoffeeScript类型错误:未定义不是函数。 iOS Safari 评估功能。咖啡脚本
【发布时间】:2015-09-01 09:17:14
【问题描述】:

我在 iOS safari 上尝试评估是否存在与 at 正则表达式字符串匹配的数组时出现错误。

代码: this.productArray = ['array', 'with', 'stuff']

this.splittedString = string.split('/(\n\r|\r\n)|( )/igm')

    _.each this.splittedString, (word, index) =>
        for word of this.productArray
            if this.splittedString[index].includes(this.productArray[word])
                this.pushToArray('matchedProducts', this.productArray[word])

它在 Chrome 上运行没有问题,但 iOS Safari 会出现 TypeError:

TypeError: undefined is not a function(评估 '_this.splittedString[index].includes(_this.productArray[word])')

这太奇怪了。而且我只是无法弄清楚错误。谢谢。

【问题讨论】:

    标签: javascript ios safari coffeescript typeerror


    【解决方案1】:

    includes 字符串方法是 ES6 标准的一部分,Safari 不支持 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)

    【讨论】:

    • 不错!谢谢你。通过从 this.splittedString[index].includes(this.productArray[word]) 更改为 - this.splittedString[index].indexOf(this.productArray[word] >= 0) 它起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 2017-05-01
    • 2020-04-02
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多