Array.prototype.includes-不使用babel转换 [英] Array.prototype.includes - not transformed with babel

查看:151
本文介绍了Array.prototype.includes-不使用babel转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何将此代码转换为Node.js v4 env中的兼容代码:[].includes('anything')

I cannot figure out how to get this code to transform to compatible code in Node.js v4 env: [].includes('anything')

因为这会在Node.js v4 Error: includes is not a function...

Becuase this throws an error in Node.js v4 Error: includes is not a function...

有人可以帮助我理解为什么babel不能转换.includes()吗?我尝试使用babel-preset-es2015和babel-preset-es2016以及babel repl:

Can anyone help me understand why babel does not transform .includes()? I have tried using babel-preset-es2015 and babel-preset-es2016 as well as the babel repl: Example babel repl code usage

推荐答案

您需要导入babel-polyfill才能使用静态方法(如Array.fromObject.assign),实例方法(如Array.prototype.includes).

You need to import babel-polyfill to use static methods like Array.from or Object.assign, instance methods like Array.prototype.includes.

如果您不想修改全局变量,请签出transform-runtime插件.这意味着您将无法使用上述的实例方法,例如Array.prototype.includes.

If you don't want to modify globals, checkout the transform-runtime plugin. This means you won't be able to use the instance methods mentioned above like Array.prototype.includes.

这篇关于Array.prototype.includes-不使用babel转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆