我在 iOS Safari 上尝试评估正则表达式字符串数组中是否存在匹配项时出现错误。
代码: 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:
类型错误:未定义不是函数(正在计算“_this.splittedString[index].includes(_this.productArray[word])”)
这太奇怪了。而且我只是无法弄清楚错误。谢谢。
最佳答案
includes
字符串方法是 ES6 标准的一部分,Safari 不支持它 ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes )
关于javascript - TypeError: Undefined 不是一个函数。 iOS Safari 评估功能。 CoffeeScript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32327801/