JavaScript中没有大括号的Lambda函数语法 [英] Lambda function syntax in JavaScript without curly braces
问题描述
f = function(x)x + 1;
f(17)//给出18
有谁知道这到底是怎么回事?这是在任何标准?其他浏览器是否也接受它? (我测试了IE 8,它给了我语法错误)
这不是标准的一部分。该文档位于 https://developer.mozilla.org/en /New_in_JavaScript_1.8#Expression_closures_%28Merge_into_own_page.2fsection%29
关于在这些行中添加一些语法的讨论甚至更短的标准。请参阅 http://wiki.ecmascript.org/doku.php?id=strawman: short_function_syntax
I just found out that the following (awesome) syntax is accepted by Firefox
f = function(x) x+1;
f(17) //gives 18
Does anyone know what the hell is going on here? Is this in any standard? Do other browsers also accept it? (I tested IE 8 and it gave me syntax error)
This isn't part of a standard. The documentation is at https://developer.mozilla.org/en/New_in_JavaScript_1.8#Expression_closures_%28Merge_into_own_page.2fsection%29
There's discussion about adding some syntax along these lines or even shorter to the standard. See http://wiki.ecmascript.org/doku.php?id=strawman:shorter_function_syntax
这篇关于JavaScript中没有大括号的Lambda函数语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!