最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Linq.js Enumerable.from() - Stack Overflow

programmeradmin0浏览0评论

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 mands 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?

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 mands 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?

Share Improve this question edited Jun 21, 2018 at 9:13 Steven 2,1213 gold badges23 silver badges35 bronze badges asked Dec 8, 2013 at 8:06 TomTom 16.3k15 gold badges75 silver badges115 bronze badges 1
  • 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 Commented Dec 19, 2013 at 4:09
Add a ment  | 

2 Answers 2

Reset to default 3

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

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

Let me know if I could be of any more help

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(...);
发布评论

评论列表(0)

  1. 暂无评论