奇怪的 javascript 函数定义语法的文档? () => {}
Documentation for strange javascript function definition syntax? () => {}
因此,前几天我正在阅读一个 js 文件,并注意到一个非常奇怪的语法,我认为这是一个简写函数定义。我认为它可能与某种库有关,但我使用纯 javascript 在 JSFiddle 中编写了一个示例,它确实有效。
有人以前看过这个吗?你能指出它的文档以便我可以阅读更多关于它的信息吗? '='
后面的'>'
符号有什么意义?
样本:
() => {
alert('hi');
}
它在我的浏览器中不起作用 (Chrome)。这可能意味着您正在使用 Firefox。 Mozilla 可以快速实现新的 Ecmascript 特性。箭头是 Ecmascript 6 的一个特性。
Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.
您可以在此处阅读有关 Ecmascript 6 功能的更多信息:
https://github.com/lukehoban/es6features
编辑:由于此时对箭头的原生支持有限,您可能在阅读的 js 文件中遇到了 CoffeeScript。
因此,前几天我正在阅读一个 js 文件,并注意到一个非常奇怪的语法,我认为这是一个简写函数定义。我认为它可能与某种库有关,但我使用纯 javascript 在 JSFiddle 中编写了一个示例,它确实有效。
有人以前看过这个吗?你能指出它的文档以便我可以阅读更多关于它的信息吗? '='
后面的'>'
符号有什么意义?
样本:
() => {
alert('hi');
}
它在我的浏览器中不起作用 (Chrome)。这可能意味着您正在使用 Firefox。 Mozilla 可以快速实现新的 Ecmascript 特性。箭头是 Ecmascript 6 的一个特性。
Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.
您可以在此处阅读有关 Ecmascript 6 功能的更多信息: https://github.com/lukehoban/es6features
编辑:由于此时对箭头的原生支持有限,您可能在阅读的 js 文件中遇到了 CoffeeScript。