Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any use in importing both ES6 and ES7 core-js polyfills?

Is it useful or redundant to import the ES6 polyfill for Object

import 'core-js/es6/object';

and also the ES7 polyfill for Object?

import 'core-js/es7/object';

Does the ES7 polyfill cover all of the ES6 features and can I leave the ES6 polyfill out, or does the ES6 polyfill add features not present in the ES7 polyfill?

like image 985
Ionaru Avatar asked Aug 08 '17 11:08

Ionaru


People also ask

What is the difference between the ES6 and ES7 polyfill?

Thus, the ES6 polyfill indeed adds only methods introduced in ES6 and this is not covered by the ES7 polyfill. That one only adds methods introduced in ES7.

Do I need Babel to use ES6?

Let’s take a look at what’s officially part of ES6. By the way, all those features are officially supported across browsers. In other words, you do not need Babel to use any of them (unless you support IE 11, which is missing a few). The ability to create and inherit classes. ES6 modules with import and export.

Is there a use for the ES7 prefix in core-JS@2?

This answer concerns core-js@2. Starting from core-js@3, there are no longer separate ES6 and ES7 prefixes. This is due to how ECMAScript developed. You can find more details in the core-js@3, babel and a look into the future post. Yes, there is a use. Simply compare core-js/es6/object.js to core-js/es7/object.js.

What are the core features of next generation JavaScript in ES6?

Here are the core features of the next generation JavaScript in ES6 and ES7. var is a way to create variable in JavaScript. Even to create constant we use var in old version of JS. ES6 has introduced two keywords let and const. (... var still works fine, but you are highly encouraged to use let and const …)


2 Answers

This answer concerns core-js@2. Starting from core-js@3, there are no longer separate ES6 and ES7 prefixes. This is due to how ECMAScript developed. You can find more details in the core-js@3, babel and a look into the future post.

Yes, there is a use. Simply compare core-js/es6/object.js to core-js/es7/object.js.

The ES6 object polyfill provides:
•  Symbol
•  Object.create
•  Object.defineProperty
•  Object.defineProperties
•  Object.getOwnPropertyDescriptor
•  Object.getPrototypeOf
•  Object.keys
•  Object.getOwnPropertyNames
•  Object.freeze
•  Object.seal
•  Object.preventExtensions
•  Object.isFrozen
•  Object.isSealed
•  Object.isExtensible
•  Object.assign
•  Object.is
•  Object.setPrototypeOf
•  Object.prototype.toString

On the other hand, the ES7 object polyfill provides:
•  Object.getOwnPropertyDescriptors
•  Object.values
•  Object.entries
•  Object.prototype.__defineGetter__
•  Object.prototype.__defineSetter__
•  Object.prototype.__lookupGetter__
•  Object.prototype.__lookupSetter__

Thus, the ES6 polyfill indeed adds only methods introduced in ES6 and this is not covered by the ES7 polyfill. That one only adds methods introduced in ES7.

core-js appears to be structured the same way for other classes.

like image 132
Just a student Avatar answered Oct 17 '22 07:10

Just a student


The polyfills from core-js for different ECMAScript versions are mostly distinct. For example take a look at the object polyfill for ES6 and ES7.

So you need to import both if you want to have the features from ES6 and ES7 polyfilled.

like image 20
cyr_x Avatar answered Oct 17 '22 08:10

cyr_x