Lambda Expression in JS, C# and C++

JS has anonymous functions, but it still looks a little bit tedious.

I know a code can be written like below in JS 1.8:
var test = function(x) x*x; // JS 1.8 syntax, like in Firefox
But if it borrows C#'s lambda expression, it is more simply written like below:
var test = (x) => x*x; // pseudo 
Also, here's C++'s lambda expression:
auto test = [](int x){return x*x;}; // C++
For [], JS already has call(thisArg,) and apply(call(thisArg,) for switch of context, maybe no need for it (but it can be a syntax sugar or shorthand for thisArg).
For C++'s (), {} and ;, they are tedious, little need for borrowing them; these punctuations should be cut down when they can be grammatically reduced and ignored.

Hmmm, JS and C++ should learn from C# even though I don't like IE, Outlook and Windows' system architecture :P.

Comments

Popular posts from this blog

Hardcoding Data Like Images and Sounds into HTML or CSS

DDS for GIMP (Mountain Lion, Native, no X11 GUI)

Make It Work: Global .gitattributes