JavaScript中没有大括号的Lambda函数语法 [英] Lambda function syntax in JavaScript without curly braces

查看:118
本文介绍了JavaScript中没有大括号的Lambda函数语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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屋!

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