admin管理员组文章数量:1327524
The title is pretty self explanatory but still, consider this sample code:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
export default class App extends React.Component {
render() {
return (
<Text>
{Object.fromEntries("test")}
</Text>
);
}
}
Check it out on Expo Snacks
By opening it on an Android device, I get the error that the fromEntries
function does not exist on Object
:
But on iOS, it does exist:
(bad parameter supplied to it, but it exists, nevertheless)
So what's happening here? Aren't JS engines supposed to be identical between the 2 platforms? What other known discrepancies like these exist?
The title is pretty self explanatory but still, consider this sample code:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
export default class App extends React.Component {
render() {
return (
<Text>
{Object.fromEntries("test")}
</Text>
);
}
}
Check it out on Expo Snacks
By opening it on an Android device, I get the error that the fromEntries
function does not exist on Object
:
But on iOS, it does exist:
(bad parameter supplied to it, but it exists, nevertheless)
So what's happening here? Aren't JS engines supposed to be identical between the 2 platforms? What other known discrepancies like these exist?
Share Improve this question edited May 31, 2019 at 10:27 iuliu asked May 30, 2019 at 13:50 iuliuiuliu 7,1658 gold badges51 silver badges72 bronze badges 4- Just to add browsers are by no-means the same. They all have varying JS engines, rendering engines etc etc. They all have their own priorities on implementing the spec and their own agenda on their preferred version of the spec. caniuse is a good resource for browser pat. – ste2425 Commented May 30, 2019 at 13:55
- Check the official spec-pliant polyfill: github./es-shims/Object.fromEntries – Christian C. Salvadó Commented May 30, 2019 at 13:59
- it just depends what javascript engine is used in the particular OS, some newer Android version support this, some don´t – CampSafari Commented May 30, 2019 at 21:37
- This question is about REACT-NATIVE guys, what browsers? What Android version? The engine is shipped with the app itself.. – iuliu Commented May 31, 2019 at 10:26
3 Answers
Reset to default 6Most likely you have an old or not-fully-supported engine (check the docs). You can make an ES6 polyfill like this:
Object.fromEntries = Object.fromEntries || arr => arr.reduce((acc, [k, v]) => (acc[k] = v, acc), {});
Or an ES5 polyfill like this:
Object.fromEntries = Object.fromEntries || function(arr) {
return arr.reduce(function(acc, curr) {
acc[curr[0]] = curr[1];
return acc;
}, {});
};
just add the babel preset to your babel config: https://www.npmjs./package/babel-plugin-transform-object-from-entries
Functions like .flat(), Object.fromEntries
, and some new ones are not yet supported by most browsers and Javascript engines. Which means we might see it being supported in the next update of android or iOS Javascript engines. support chart
本文标签: javascriptObjectfromEntries only available on iOS (react nativeNOT WEB)Stack Overflow
版权声明:本文标题:javascript - Object.fromEntries only available on iOS? (react native - NOT WEB) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742177578a2427864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论