当“使用严格”时,模板文字在IE11中不起作用指令被使用 [英] Template literals not working in IE11 when "use strict" directive is used

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

问题描述

在其他浏览器(如Chrome)中使用use strict指令时,背面刻录字符不会被识别为IE11中的有效字符。



这个行为的解释是考虑到IE11在Windows 10用户中仍然广泛使用?



< pre class =snippet-code-js lang-js prettyprint-override> use strict; function doIt(){let tt; tt = 50;警报(`$ {TT}`);警报( 测试); } doIt();


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



解决方案

如果您查看 ECMAScript 6兼容性表,您将看到IE11不支持模板文字。 使用strict; 语句并没有真正改变任何东西,因为在确定代码是否处于严格模式之前,必须首先解析,但它可以不要被解析,因为你使用的是语法,解析器不能识别。



如果你希望你的代码在IE11中工作,你应该用< a href =https://babeljs.io/ =noreferrer> Babel 。


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.

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();

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

解决方案

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.

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

这篇关于当“使用严格”时,模板文字在IE11中不起作用指令被使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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