2017-10-11 6 views
3

選択した製品に基づいて商品詳細オブジェクトを分類しようとしています。オブジェクト1011にメソッド 'startsWith'がありません

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を超える作業が、アンドロイド4.4でエラーが発生しますだ:

オブジェクト1011は 'のstartsWith'

1011が私の製品コードである方法はありません。

誰にもその理由が分かりますか?

+0

'console.log(String.prototype.startsWith);と' console.log(typeof prodCode); 'の出力を共有できますか? – gurvinder372

+1

Polyfillで試してみるhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill – Satpal

答えて

0

Androidのバージョン間では、javascriptエンジンが常に同じではなく、最新の機能が常に利用可能なわけではありません。

同じ問題が発生しました。startsWithを呼び出す前にポリフィルを追加する必要があります。

Mozillaのページのポリフィルセクションをチェックしません:http://kangax.github.io/compat-table/es6/#test-String.prototype.startsWithString.prototype.startsWithによるとhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

0

にはアンドロイド4.4で実装される可能性があります。これはconsole.log(typeof String.prototype.startsWith === 'function')で確認できます。

関連する問題