JavaScript中是否有类似C#的lambda语法? [英] Is there a C#-like lambda syntax in JavaScript?

查看:149
本文介绍了JavaScript中是否有类似C#的lambda语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有支持lambda语法的JavaScript框架或后期处理器,如C#?

Is there a framework or post processor for JavaScript that supports lambda syntax like in C#?

CoffeeScript中的函数定义看起来像lambdas但是我还没有考虑过他们彻底。

Function definitions in CoffeeScript seem to look like lambdas but I have not looked into them thoroughly.

任何人都可以告诉我,我可以在JavaScript中使用lambda语法吗?

Can anyone tell me, can I use lambda syntax in JavaScript?

推荐答案

具有类似语法的Lambda函数包含在 ECMAscript 6 ,它们被称为箭头功能。例如:

Lambda functions with similar syntax are included in ECMAscript 6, they're known as "arrow functions". An example:

[duck,cat,goat]。filter(el => el.length> 3 ); 返回 [duck,goat]

目前支持最近版本的 Firefox Chrome

There's currently support in recent versions of Firefox and Chrome.

要在针对旧浏览器的JavaScript中使用此语法,可以使用可将ES 6编译为更广泛支持的版本的工具 - 例如工具 Babel Traceur

To use this syntax in JavaScript that's targeting older browsers there are tools that can compile ES 6 to a more widely supported version - for example the tools Babel or Traceur.

这篇关于JavaScript中是否有类似C#的lambda语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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