Linq.js Enumerable.from()

8.4k views Asked by At

I am new to this very very nice Linq.js library that I have just discovered. I am following the examples to write queries like:

Enumerable.from(jsonArray).select(...); // noice

Can I do this shortcut?

jsonArray.select(...); // error as expected

I read the tests in library, seems like pretty much every call starts with Enumerable.someCommand();. I am wondering if the linq commands have been applied to the correct prototypes in js, so I can call them in the style of 2nd line of code. am I not aware of it because I am a newbie?

2

There are 2 answers

0
NYTom On BEST ANSWER

I am the creator of the open source project http://www.jinqJs.com.

You could simply do jinqJs().from(jsonArray).select();

Let me know if I could be of any more help

0
Jeff Mercado On

If your concern is that Linq.js doesn't extend the Array prototype, I think it's misplaced. It's not exactly a light framework, kinda the same reason why jquery doesn't do the same thing. You shouldn't expect anything to work on just anything.

If you wanted to make bridging that gap a little nicer, it should be safe to add some methods to convert to the other.

if (!Array.prototype.AsEnumerable) { // not likely to be used by others
    Array.prototype.AsEnumerable = () => Enumerable.From(this);
}

Then that would allow you to do:

jsonArray.AsEnumerable().Select(...);