不带花括号的 JavaScript 中的 Lambda 函数语法 [英] Lambda function syntax in JavaScript without curly braces
问题描述
我刚刚发现 Firefox 接受以下(很棒的)语法
I just found out that the following (awesome) syntax is accepted by Firefox
f = function(x) x+1;
f(17) //gives 18
有谁知道这到底是怎么回事?这是任何标准吗?其他浏览器也接受吗?(我测试了 IE 8,它给了我语法错误)
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)
推荐答案
这不是标准的一部分.文档位于 https://developer.mozilla.org/en/New_in_JavaScript_1.8#Expression_closures_%28Merge_into_own_page.2fsection%29
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
有关于在这些方面添加一些语法甚至比标准更短的语法的讨论.参见 http://wiki.ecmascript.org/doku.php?id=strawman:short_function_syntax
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屋!