简体   繁体   English

支持ES 6的Javascript片段运行器(如jsFiddle)

[英]Javascript snippet runner supporting ES 6 (like jsFiddle)

Apparently, neither jsFiddle, nor codepen.io support ES6 syntax (eg running let x = 10 will throw an error - see for yourself ). 显然,jsFiddle和codepen.io都不支持ES6语法(例如,运行let x = 10会抛出错误 - 请亲自看看 )。

Obvious choice would be es6fiddle , but it produces clearly false results (block-scoped variable i stays defined out of scope). 明显的选择是es6fiddle ,但它会产生明显错误的结果 (块范围的变量i保持定义超出范围)。

Is there any snippet runner at all, supporting ES6? 是否有任何片段转轮,支持ES6?

You could try Babel. 你可以试试Babel。 I don't know how it works under the hood, but Ember.js is using it as an ES6 polyfill, so it should be pretty reliable. 我不知道它是如何工作的,但Ember.js正在使用它作为ES6 polyfill,所以它应该是非常可靠的。 They provide a web-based console for you to play around with. 它们提供了一个基于Web的控制台供您玩耍。 It shows you what your ES6 code ends up being transformed into: https://babeljs.io/repl/ 它向您展示了您的ES6代码最终被转换为: https//babeljs.io/repl/

The particular problem you are seeing is due to a bug in Traceur , the ES6 to ES5 transpiler that many snippet runners use to add "ES6 support." 你看到的特殊问题是由于Traceur ,ES6到ES5转换器中的一个错误导致许多代码片段用户添加“ES6支持”。 You'll find that such runners are generally limited by the software running them, and in the case of Traceur, that means usually-excellent, but sometimes-buggy, ES6 support. 你会发现这样的跑步者通常受到运行它们的软件的限制,而在Traceur的情况下,这意味着通常非常好,但有时候有缺陷的ES6支持。

You can set JavaScript transpilers with http://codepen.io now. 您现在可以使用http://codepen.io设置JavaScript转换器。 One of them is babel which allows ES6. 其中一个是允许ES6的babel。 The process is transparent. 这个过程是透明的。

You have to go to settings then use the JavaScript tab. 您必须转到设置然后使用JavaScript选项卡。

We can use jsFiddle itself to run ES6 snippet. 我们可以使用jsFiddle本身来运行ES6片段。 Change the language from JavaScript to Babel. 将语言从JavaScript更改为Babel。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM