旧的安卓版本浏览器没有一些JS功能?



在奥利奥设备上测试了一个带有包含html文件的web视图的应用程序后,一切都可以正常工作。但是,当使用Kitkat设备(模拟器(时,我收到错误Possible Unhandled Promise Rejection: "Object function Object() { [native code] } has no method 'entries'"

这表面上是由于我在 html 中使用了Object.entries()。有什么办法可以解决这个问题吗?Kitkat 模拟器上的浏览器版本是 4.4.2-4729339,模拟器是 Android Studio 上的默认模拟器。

为了使新功能在旧浏览器中工作,您可以使用所谓的Polyfills这些功能主要在github或Mozilla开发人员网络上找到。

您正在寻找的是Object.entries()填充物:

if (!Object.entries)
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};

(代码取自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill(

一般来说,我建议您使用 caniuse.com 可以检查哪个浏览器支持哪个功能。

最新更新