【问题标题】:Is there any use in importing both ES6 and ES7 core-js polyfills?导入 ES6 和 ES7 core-js polyfill 有什么用?
【发布时间】:2018-01-15 23:21:04
【问题描述】:

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 中不存在的功能?

【问题讨论】:

    标签: javascript polyfills


    【解决方案1】:

    来自core-js 的针对不同 ECMAScript 版本的 polyfill 大多是不同的。例如,看看 ES6ES7 的对象 polyfill。

    所以如果你想拥有 ES6 和 ES7 的特性,你需要同时导入。

    【讨论】:

      【解决方案2】:

      这个答案涉及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 中引入的 only 方法,而这 not 被 ES7 polyfill 覆盖。那一个添加了 ES7 中引入的方法。

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

      【讨论】:

      • 我们必须使用 es7 和 es6 来获得 new Map() 支持,我相信 Object.entries 提供了这种支持。感谢您的回答!
      • Github 链接已损坏。看起来他们可能已经重新分类了。
      猜你喜欢
      • 1970-01-01
      • 2016-05-17
      • 2020-04-28
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      相关资源
      最近更新 更多