HTML5,ES6模板字符串polyfill [英] HTML5, ES6 template string polyfill

查看:376
本文介绍了HTML5,ES6模板字符串polyfill的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们的应用程序,我们需要使用新功能 模板字符串

For our application we need to use new feature template string.

var verLongKey= `834r845784576485
y84ery5845y485yu843
483y53485684576845
jhu87843647356756745==457485,mh
ererthe8t0998785==ery8`;

但旧浏览器(如Android默认浏览器)不支持模板字符串。

But old browsers(like android default browsers) don't support template string.

如何为此功能获取polyfill?
尝试 babel 。我们让这个polyfill适用于所有功能,但模板字符串
目前使用 modernizr 检测支持并显示警报以使用其他浏览器。
这种方法对用户来说很烦人。如何才能在非支持浏览器上使用polyfill?

How can I get polyfill for this feature? Tried babel. We got this polyfill working for all features but template string. Currently using modernizr to detect support and show alert to use other browser. This approach is annoying for users. How can i get some polyfill to make this work on the non supporting browsers?

是什么让我们这个模板字符串
问题是我无法使用这些工具( trceur babel )生成此文件来自 puppet 的制作。我们无法在那里运行这些转发器。想在浏览器端添加一些polyfill。该密钥包含一些 \ n 字符,需要保留它们。我想要一些polyfill所以,我可以在configs js文件之前包含。

What made us this template strings. The problem is i can't use these tools(trceur,babel) as this file is generated on the production from puppet. There is no way we will run these transpilers there. want to add some polyfill on the browser side. the key contains some \n characters in it need to preserve those. I want some polyfill so, i can include before the configs js file.

推荐答案

有3种主要的ES6 polyfill可以给你模板字符串支持,但没有一个完全支持,您可以在 kangax的ECMAScript支持表。

There are 3 main ES6 polyfills that can give you template string support but none of them have full support as you can see at kangax's ECMAScript support table.


  • Traceur - 这是Google的ECMAScript polyfill,它支持一些ECMAScript 6和ECMAScript的下一个功能,它有4/5的支持对于模板字符串,没有toString转换。

  • Traceur - This is Google's ECMAScript polyfill that support some ECMAScript 6 and ECMAScript next features, it have 4/5 support for template strings, there is no toString conversion.

Babel - 另一个ECMAScript polyfill,一般有更多支持,但也只有4/5支持模板字符串,也没有toString转换。

Babel - Another ECMAScript polyfill, have more support in general but also have only 4/5 support for template strings, also no toString conversion.

es6-shim - 我不确定它是否已经开发了,但它无论如何都没有模板字符串。 / p>

es6-shim - I'm not sure if it's even developed anymore, but it doesn't have template strings anyway.

但是在使用模板字符串之前你可能要三思而后行,它只是st的语法糖使用+添加变量和\以使​​用多行。

But you might want to think twice before using template string, it just a syntactic sugar for string with + to add variables and \ to have multi lines.

这篇关于HTML5,ES6模板字符串polyfill的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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