简体   繁体   English

`String.prototype.at` 并非在所有浏览器中都实现。 是否有 @babel/plugin 可以将其转换为 ES5 javascript?

[英]`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.

相关问题 Babel JS —只需将JavaScript STRING转换为es5(使用nodejs) - Babel JS — simply convert JavaScript STRING to es5 (USING nodejs) 转换成 ES5 语法 Javascript - transform into ES5 syntax Javascript 如何使用 babel 以编程方式将 es6 转换为 es5? - How to use babel to transform es6 to es5 programmatically? 是否可以在ES5 JavaScript中实现对象键的惰性迭代器而无需将对象的所有键立即加载到内存中? - Can a lazy iterator for the keys of an object be implemented in ES5 JavaScript without loading all keys of the object into memory at once? javascript es5 async插件架构 - javascript es5 async plugin architecture JavaScript 原型 Inheritance scope 内 ES5 Class - JavaScript Prototype Inheritance scope inside ES5 Class 使用Babel在线将ES6映射到ES5 - Transpiling ES6 to ES5 online with Babel 是将ES6编译为ES5所需的babel-cli plus预设吗? - Is babel-cli plus presets all I need to compile ES6 to ES5? 当代码为字符串时,重新编译Javascript ES6至ES5代码 - Recompiling Javascript ES6 to ES5 code when the code is a string 2D图像旋转JavaScript可在所有浏览器中使用。 修复我的代码所需的帮助 - 2D image rotation javascript to work in all browsers. Help needed to fix my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM