As people have tried experimenting with fluent interfaces for everything, it was only a matter of time before javascript followed suit. A few weeks ago I became impressed with Soapi.js, a fluent interface for Stack Exchange. Today, I was absolutely blown away by the promise of jLinq.

jLinq is exactly what it sounds like: LINQ for javascript. Taking a few examples from the jLinq website, here are snippets to do filtering and joins on JS arrays.

jlinq.from(data.users)
     .starts("first", "a")
     .select()
jlinq.from(data.users)
     .join(
          data.orders,
          "orders",
          "id", 
          "ownerId"
     )
     .select(function(rec) {
          return {
               first:rec.first,
	       total:rec.orders.length
     };
});

jLinq also does the usual where-clause and supports and, or, and not operators. You can even do single and multi-field sorting. If jLinq’s performance matches its elegance, it would replace a number of jQuery functions. Things like filter(), grep(), and inArray() could all be replaced to a certain extent. jLinq has the potential to solve half of the problems developers typically write inefficient code for (filtering, sorting, merging).

It’s 1:36am. I have to get up in 5 hours to catch a plane. And I’m gushing about a javascript library. jLinq is a brilliant idea indeed.

Leave a comment