javascript - 同时导入 ES6 和 ES7 core-js polyfill 有什么用吗?

标签 javascript polyfills

Object 导入 ES6 polyfill 是否有用或多余?

import 'core-js/es6/object';

还有 Object 的 ES7 polyfill?

import 'core-js/es7/object';

ES7 polyfill 是否涵盖了所有 ES6 功能,我可以不使用 ES6 polyfill,还是 ES6 polyfill 添加了 ES7 polyfill 中不存在的功能?

最佳答案

这个答案涉及 core-js@2。从core-js@3开始,不再有单独的ES6和ES7前缀。这是由于 ECMAScript 的开发方式。您可以在 core-js@3, babel and a look into the future 中找到更多详细信息发布。

是的,有一个用途。简单比较core-js/es6/object.jscore-js/es7/object.js .

ES6 对象 polyfill 提供:
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

另一方面,ES7 对象 polyfill 提供:
Object.getOwnPropertyDescriptors
Object.values
Object.entries
Object.prototype.__defineGetter__
Object.prototype.__defineSetter__
Object.prototype.__lookupGetter__
Object.prototype.__lookupSetter__

因此,ES6 polyfill 确实添加了 ES6 中引入的方法,ES7 polyfill 涵盖这些方法。那个添加了 ES7 中引入的方法。

core-js 的结构似乎与其他类的结构相同。

关于javascript - 同时导入 ES6 和 ES7 core-js polyfill 有什么用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45567462/

相关文章:

asp.net - Angular 6 - IE11 上的 GET/POST 问题 - 符号(rxSubscriber)未定义

javascript - 不调用 native 函数的普通 Cordova 插件

javascript - 为 .includes 添加了 Poly-fill,但尽管在所有其他区域都得到了解决,但仍然在一个区域出现错误

internet-explorer-11 - Web Components 真的可以在 IE11 和 Edge 中使用吗?

jquery - Respond.js 和 Modernizr 无法在 IE8 上进行媒体查询

css - IE11 - CSS 变量是否存在 polyfill/脚本?

javascript - 文本到 Outlook 正文

javascript - html 渲染事件

javascript - 防止用户在多个选项卡中运行相同的 javascript 调用的最佳方法是什么?

javascript - 如何通过 bot API 使用 Google App 脚本将文件从电报下载到 Gdrive