[英]`String.prototype.at` is not implemented in all browsers. Is there a @babel/plugin that will transform this down to ES5 javascript?
At the time of this question String.prototype.at
is not implemented in all browsers.在提出这个问题时,
String.prototype.at
并未在所有浏览器中实现。
I would like to use the at
function on the String prototype within a React app that uses babel to transform modern ecmascript into older more browser compatible versions of javascript.我想在使用 babel 将现代 ecmascript 转换为更旧的浏览器兼容的 javascript 版本的 React 应用程序中的 String 原型上使用
at
函数。
I have been unsuccessful in finding a babel plugin that would do this for me.我一直没有成功找到一个可以为我做这件事的 babel 插件。
Is there a @babel/plugin that will transform the String prototype at
function down to more browser compatible ES5 javascript?是否有一个@babel/plugin 可以将函数中的字符串原型转换
at
更多与浏览器兼容的 ES5 javascript?
String.prototype.at
is equal this function String.prototype.at
等于这个函数
let text = "hello, how are you";
function at(a, b) {
return a.charAt(b < 0 ? a.length-Math.abs(b) : b);
}
console.log(at(text, -3));
console.log(text.at(-3));
Babel is for syntax-level transformations, not browser API polyfills. Babel 用于语法级别的转换,而不是浏览器 API 填充。
You can consider using a polyfill service like Polyfill.io , or alternatively, simply use the polyfill code from the relevant proposal .您可以考虑使用Polyfill服务,例如Polyfill.io ,或者简单地使用相关提案中的polyfill 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.