模板文字语法在 IE11 中不起作用 [英] Template literals syntax is not working in IE11

查看:33
本文介绍了模板文字语法在 IE11 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当它在其他浏览器(例如 Chrome)中工作时,当使用use strict"指令时,反勾号字符在 IE11 中不被识别为有效字符.

The back-tick character is not recognized as a Valid Character in IE11 when using the "use strict" directive while it works in other browsers, such as Chrome.

考虑到 IE11 即使在 Windows 10 用户中仍然广泛使用,对这种行为的解释是什么??

What is the interpretation of this behavior taking into consideration that IE11 is still widely used even among Windows 10 users??

        "use strict";

        function doIt() {
          let tt;
          tt = 50;
          alert(`${tt}`);
          alert("test");
        }
       doIt();

错误:{"message": "无效字符","filename": "http://stacksnippets.net/js","lineno": 18,科诺":17}

Error: { "message": "Invalid character", "filename": "http://stacksnippets.net/js", "lineno": 18, "colno": 17 }

推荐答案

如果你看一下 ECMAScript 6 兼容性表,您会看到 IE11 不支持模板文字."use strict"; 语句并没有真正改变任何东西,因为在确定代码是否处于严格模式之前,必须先对其进行解析,但无法解析,因为您正在使用解析器无法识别的语法.

If you look at the ECMAScript 6 compatibility table, you'll see that template literals are not supported by IE11. The "use strict"; statement doesn't really change anything, because before it is determined whether a code is in strict mode, it has to be parsed first, but it can't be parsed, because you're using syntax that the parser doesn't recognize.

如果您希望您的代码在 IE11 中运行,您应该使用 Babel 进行转译.

If you want your code to work in IE11, you should transpile it with Babel.

这篇关于模板文字语法在 IE11 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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