目前哪些浏览器支持 JavaScript 的“let"关键字? [英] What browsers currently support JavaScript's 'let' keyword?

查看:22
本文介绍了目前哪些浏览器支持 JavaScript 的“let"关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,不必担心 Internet Explorer,并且正在研究 Internet Explorer1 中没有的 A+ 级浏览器中的一些功能.

I'm developing an app and don't have to ever worry about Internet Explorer and was looking into some of the features present in A+ grade browsers that aren't in Internet Explorer1.

我想使用的这些功能之一是 JavaScript 的 let 关键字

One of these features I wanted to play around with is JavaScript's let keyword

我似乎无法让他们的任何让"示例在 Firefox 3.6 中工作(用户代理字符串:Mozilla/5.0(Windows;U;Windows NT 5.1;en-US;rv:1.9.2)Gecko/20100115 Firefox/3.6(.NET CLR 3.5.30729)).我得到 SyntaxError: missing ;执行 let foo = "bar" 时的 before 语句.

I can't seem to get any of their 'let' examples to work in Firefox 3.6 (User-Agent string: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)). I get SyntaxError: missing ; before statement when executing let foo = "bar".

那么,哪些浏览器支持 let 关键字?(还是我做错了什么?)

So, what browsers support the let keyword? (Or am I doing something wrong?)

推荐答案

EDIT:所有现代浏览器都支持 letconstECMAScript 2015 (ES6)<的一部分/a> 规范.

EDIT: let and const are supported by all modern browsers and are part of the ECMAScript 2015 (ES6) specification.

基本上,如果你不需要支持 IE11 以下的任何东西,letconst 现在可以安全使用.

Basically if you don't need to support anything below IE11, let and const are safe to use nowadays.

IE11 上,当与 for 循环一起使用时,let 有一个小问题,该变量未绑定到 for 块如您所料,它的行为与 var 一样...

On IE11 there's a small quirk with let when used with for loops, the variable is not bound to the for block as you would expect, it behaves as var did...

另见:letconst 支持.

2010 年的旧答案:这些扩展不是 ECMA 标准的,只有 Mozilla 实现支持它们.

Old and outdated answer from 2010: Those extensions are not ECMA-Standard, they are supported only by the Mozilla implementation.

在浏览器环境中,您应该在 script 标签中包含 JavaScript 版本号以使用它:

On browser environments you should include the JavaScript version number in your script tag to use it:

<script type="application/javascript;version=1.7">  
  var x = 5;
  var y = 0;

  let (x = x+10, y = 12) {
    alert(x+y + "
");
  }

  alert((x + y) + "
");
</script>

这篇关于目前哪些浏览器支持 JavaScript 的“let"关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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