Which ECMAScript 2015 features are safe to use?
Target systems
- Desktop web browsers: latest Firefox, Chrome, IE11+. Babel transpiling allowed if generated code is not too bloated.
- Latest Node.js.
General approach with Babel
- Use babelify
- Use external helpers
- Provide helpers for class-related things
- Modify static method copying to keep original prototypes
- Use loose mode (don't know yet how to make external helpers for normal mode, may have conflicts with prototype nonmodification fixes)
ES2015 features requiring some Babel helpers, safe to use
- classes including static methods
- template strings with tags
ES2015 features requiring no Babel helpers, safe to use
const
, let
(also supported natively by browsers, may want to disable Babel on these)
- template strings without tags
- arrow functions
- object literal extensions
- spread operator on arrays
Map
with empty constructor and its methods: get()
, set()
, forEach()
(supported natively by browsers)
- octal and binary number literals (not as Number() arg)
- block-scoped functions (not supported by Firefox, but supported by IE 11)
- destructuring (of arrays)
- default arguments
for .. of
with array-like objects, including strings; use babel-plugin-transform-for-of-array
- regexp
/u
flag (generates weird expression in place of .
)
ES2015 features requiring Babel helpers and/or other polyfills, unsafe to use
for .. of
with non-array-like objects (requires Symbol
polyfill)
String
methods like startsWith()
(may have to use core.js)
- object super (for object literals with __proto__; requires just one helper fn, but not useful to me)
- regexp
/y
flag (requires RegExp class to support this flag)
ES2015+ features not implemented in Node.js, unsafe to use
Useful links