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:
For C++'s
Hmmm, JS and C++ should learn from C# even though I don't like IE, Outlook and Windows' system architecture :P.
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 FirefoxBut if it borrows C#'s lambda expression, it is more simply written like below:
var test = (x) => x*x; // pseudoAlso, 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
Post a Comment