Is there a C#-like lambda syntax in JavaScript?
Is there a framework or post processor for JavaScript that supports lambda syntax like in C#?
Function definitions in CoffeeScript seem to look like lambdas but I have not looked into them thoroughly.
Can anyone tell me, can I use lambda syntax in JavaScript?
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);
returns ["duck", "goat"]
There's currently support in recent versions of Firefox and Chrome.
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.
You could use typescript (www.typescriptlang.org/):
function (d, i) {
return "translate(" + d.x + "," + d.y + ")";
}
would become
(d, i) => "translate(" + d.x + "," + d.y + ")"
and much more cool stuff, like typing: ... that's if you are into that