1

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?

Steven
  • 1,996
  • 3
  • 22
  • 33
Tom
  • 15,781
  • 14
  • 69
  • 111
  • Well there's reasons why the linq operations were not just thrown onto the Array prototype. I don't know if this is _the_ reason but it isn't exactly lightweight. Arrays and objects needed to be converted to `Enumerable` objects so you could operate on them and back when you're done querying. That's just the way it is. – Jeff Mercado Dec 19 '13 at 04:09

2 Answers2

3

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

NYTom
  • 524
  • 2
  • 14
0

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(...);
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272