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

查看:137
本文介绍了模板文字语法在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.

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

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, "colno":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天全站免登陆