Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 on JavaScriptCore and React Native

I'm trying to figure out what parts of ES6 are supported on React Native. I'm aware of the Babel transformations that are listed here, but I'm having a hard time figuring out what JavaScriptCore supports on its own without any transpiling. Like will JavaScriptCore support different things on different platforms and devices? Is it different on iOS 8 vs iOS9?

For instance I wrote some code that uses generator functions and ES6 collection types, and those are not part of what's listed in the Babel transformations, and it works fine in React Native on the devices where I tested. But how do I know whether it will work for all devices I'm targeting?

like image 903
alexp Avatar asked Mar 31 '16 21:03

alexp


2 Answers

As you mentioned React Native is using JavaScriptCore as Javascript engine. JavaScriptCore is also the engine used by iOS' Safari. For Andriod in general V8 is used. So you would only have to look the current feature support up in a compatability table like this one.

like image 100
Daniel Schmidt Avatar answered Sep 28 '22 10:09

Daniel Schmidt


The JavaScriptCore version does depend on your iOS version, so for example on iOS 8 you don't have access to some ES6 methods, as explained here: https://mcculloughwebservices.com/2016/11/29/adding-support-es2015-number-methods/

They even made a polyfill following their post, so just install it:

npm install --save react-native-polyfill

And load it at the beginning of your app:

import 'react-native-polyfill'

I ended up here because Number.isInteger just raised an error on the device of someone using my React Native app:

TypeError: undefined is not a function (evaluating 'Number.isInteger(u)')

They have iOS 8.1.2. Their userAgent is Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B440

However on iOS 10.3.1 (using my iPhone or the simulator), this method exists and works fine. My userAgent is Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301

Besides, according to Caniuse, this feature appeared in Safari Mobile 9.

like image 42
antoine129 Avatar answered Sep 28 '22 12:09

antoine129