Is metaprogramming possible in Javascript?

RameshVel picture RameshVel · Sep 1, 2009 · Viewed 6.9k times · Source

During my routine work, i happened to write the chained javascript function which is something like LINQ expression to query the JSON result.

var Result = from(obj1).as("x").where("x.id=5").groupby("x.status").having(count("x.status") > 5).select("x.status");

It works perfectly and give the expected result.

I was wondering this looks awesome if the code is written like this (in a more readable way)

var Result = from obj1 as x where x.status
groupby x.status having count(x.status)  > 5
select x.status;

is there a way to achieve this??

Cheers

Ramesh Vel

Answer

Georg Schölly picture Georg Schölly · Sep 1, 2009

No. JavaScript doesn't support this.

But this looks quite good too:

var Result =  from(obj1)
             .as("x")
             .where("x.id=5")
             .groupby("x.status")
             .having(count("x.status") > 5)
             .select("x.status");