by bhayden
3. October 2012 22:49

As part of an educational exercise for myself, I decided to create a library that “ports” one of my favorite features of the C# language to JavaScript.  I say “ports” because I didn’t try and emulate the syntax directly of LINQ (though with the new proposed fat arrow syntax this would be possible).  One of the things I miss most when working in other languages is the LINQ API.  While I know that there are other libraries that likely do this better (underscore) or already have it built in, I find the familiarity of .where, .first, .any, etc. to be like a nice warm blanket on a cold day.

The educational portion of this was two-fold, familiarize myself with Git and use Jasmine.  For the past couple of years in my day job I’ve been using Mercurial for source control and that spilled over into my personal projects as well.  It also helps that Bitbucketprovides  private repos for no cost. Still I felt it was high time I jumped on the Git train. 

I have one more operator to finish for JSLinq before I’d dub it feature complete (select) as I don’t have any plans to add and of the OrderBy functionality.  I debated for a while on whether to extend directly on the Array and Object prototypes or to instead wrap them in my own namespace and provide the functionality that way.  The latter is the safer way but I ultimately decided to go with the former because it feels more like LINQ to Objects to have them directly accessible as methods on every object or array.  One of the other design decisions I made was to include the methods on both the Array prototype and the Object prototype.

This decision came about because at first I was only going to apply the methods on arrays, but then I decided to add support objects after the fact.  I decided to keep them on arrays because the implementation on arrays felt cleaner to me then if I passed completely through to the Object methods which are not as clean to me.

All in all this was a fun little project that I initially thought I’d never use, but now I’m considering bringing it into some of my projects as I really do like the API that LINQ provides.  You can check out the source here.


Comments are closed