Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 3.18 KB

File metadata and controls

56 lines (39 loc) · 3.18 KB
id javascript-environment
title JavaScript Environment
layout docs
category Guides
permalink docs/javascript-environment.html
next activityindicatorios

JavaScript Runtime

When using React Native, you're going to be running your JavaScript code in two environments:

  • In the simulator and on the phone: JavaScriptCore which is the JavaScript engine that powers Safari and web views. Due to the absence of writable executable memory in iOS apps, it doesn't run with JIT.
  • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with Objective-C via WebSocket. So you are using V8.

While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

JavaScript Syntax Transformers

Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript language features.

As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check the Babel documentation for its supported transformations and more details.

Here's a full list of React Native's enabled transformations.

ES5

  • Reserved Words: promise.catch(function() { });

ES6

ES7

Custom transformer

You can also use a custom transformer file instead of the default one, in case you want to modify or extend the behavior beyond the Babel configuration. In order to do so, start the packager like this:

./node_modules/react-native/packager/packager.sh --transformer=yourtransformer.js

The path you are providing as argument will be treated as being relative to process.cwd().