简体   繁体   English

有没有办法让 babel 变换 Object.hasOwn?

[英]Is there a way to make babel transform Object.hasOwn?

preset-env only includes global altering polyfills core-js, which is not great as a library author. preset-env 仅包含全局更改 polyfills core-js,作为库作者并不出色。

https://github.com/zloirock/core-js#babelruntime talks about a babel transform for imports but none of them work on Object.hasOwn(). https://github.com/zloirock/core-js#babelruntime谈到了用于导入的 babel 变换,但它们都不适用于 Object.hasOwn()。

You can transform any code into another code using babel, that is exactly the role of babel transformations.你可以使用 babel 将任何代码转换为另一个代码,这正是 babel 转换的作用。 Seems that there is one plugin available (disclaimer: I've never used it) but you can how the function would look like after the babel transformation, or you could also write your own babel-plugin for it.似乎有一个可用的插件(免责声明:我从未使用过它)但您可以了解 function 在 babel 转换后的样子,或者您也可以为它编写自己的 babel-plugin。

You could also ship a polyfill together with your library, or require it as a dependency of your library.您还可以将 polyfill 与您的库一起发布,或者将其作为库的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM