为 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.js
至 core-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/