gpt4 book ai didi

javascript - 对象 1011 没有方法 'startsWith'

转载 作者:行者123 更新时间:2023-12-02 03:24:06 24 4
gpt4 key购买 nike

我正在尝试根据所选产品对我的产品详细信息对象进行分类。

if (prodCode.startsWith("1") || prodCode.startsWith("4")) {
ProductDetails = obj.MachineDetails;
}
else if (prodCode.startsWith("6")) {
if (prodCode.charAt(3) == '3' || prodCode.charAt(3) == '4') {
ProductDetails = obj.BoxDetails;
}
else {
ProductDetails = obj.SomeDetails;
}
}
else if (prodCode.startsWith("2") || prodCode.startsWith("3")) {
ProductDetails = obj.SomeOtherDetails;
}

它在 Android 4.4 以上工作正常,但在 android 4.4 中出现错误:

Object 1011 has no method 'startsWith'

1011 是我的产品代码。

有人知道为什么会发生这种情况吗?

最佳答案

在 Android 版本之间,JavaScript 引擎并不总是相同,并且最新功能并不总是可用。

我遇到了同样的问题:你必须在调用startsWith之前添加一个polyfill。

检查 Mozilla 页面上的 polyfill 部分:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

关于javascript - 对象 1011 没有方法 'startsWith',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46682698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com