不能使用“let” Safari中的关键字? [英] Can't use "let" keyword in Safari Javascript?

查看:1144
本文介绍了不能使用“let” Safari中的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白使用let关键字的最佳方法...

I don't understand the best way to use "let" keyword...


  • 在IE11和Chrome45中,我可以使用它罚款

  • 在Safari8.0.4中,就像旧版Chrome一样,它会出现意外使用保留字let'

  • Firefox的let关键字只能在< script type =application / javascript; version = 1.7/> 内部起作用,但这种脚本类型甚至不被识别为Javascript IE11,Chrome45,Safari8。

  • In IE11 and Chrome45 I can use it fine
  • In Safari8.0.4, like in older versions of Chrome, it gives the error "unexpected use of reserved word 'let'"
  • In Firefox the let keyword only works inside <script type="application/javascript;version=1.7"/>, but this script type isn't even recognized as Javascript in IE11, Chrome45, Safari8.

这是一个JSFiddle,它显示在行动中: https://jsfiddle.net/p6cgtyg6/1/

Here's a JSFiddle that shows it in action: https://jsfiddle.net/p6cgtyg6/1/

所以 - 我不要求用户使用现代版本的浏览器。

So -- I don't mind requiring users to use modern versions of their browsers.

如果老实说是不支持此关键字的Safari版本,我不介意排除Safari。 (这真的是真的吗?为什么大多数人都花时间在IE上呢,当Safari看起来更糟糕的是在ES6中呢?我错过了一些东西?)

And I don't mind excluding Safari if there honestly is no version of Safari that supports this keyword. (Is that really true? Why does everyone spend all their time griping about IE when Safari seems so much worse in ES6 terms? Have I missed something?).

但是如何应该允许let在Firefox中工作,而不能防止Chrome / IE? (我还没有找到关于Firefox脚本代码与Chrome的不同之处的人的链接,我预计会有更多的投诉,所以我认为我一定错过了一些明显的东西...)

But how should I allow "let" to work in Firefox while not preventing Chrome/IE? (I haven't yet found links from people griping about how Firefox script tag behaves differently from Chrome, and I'd have expected more complaints, so I figure I must have missed something obvious...)

推荐答案

关于Safari 8,只是不支持;对于该浏览器,我建议使用 Babel

Concerning Safari 8, it's just not supported ; for that browser, I'd recommend using Babel.

如果您有意见,此错误将不会被修复任何时候,你可以有一个检测Firefox的脚本,然后将脚本注入到类型属性的适当值中。

If you have the gut feeling that this bug won't be fixed anytime soon then you could have a script that detect Firefox which would then inject your script(s) with the appropriate value for the type attribute.

作为附注,我建议不要使用let块,除非你想使用这个transpiler - 不要使用表达式href =https://bugzilla.mozilla.org/show_bug.cgi?id=1023609 =nofollow>将被删除。

As a side note, I would advise not to use let blocks—unless you wanna use this transpiler—nor let expressions which will be dropped.

这篇关于不能使用“let” Safari中的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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