4 ms·
I do like how the `select` can take a string, "x > 30", vs a function(x){ return x > 30} It would be be nice if Underscore had a bit more sugar like that. But,
by jweir 14y ago
I do like how the `select` can take a string, "x > 30", vs a function(x){ return x > 30}
It would be be nice if Underscore had a bit more sugar like that. But, I also know how problematic it can be to properly parse or evaluate a string into code.
--edit--
it is using the to-function library to do this: https://github.com/component/to-function https://github.com/component/to-function
- jarin 14y agoPassing it in as a string just feels dirty to me for some reason.
- aurelianito 14y agoIt feels dirty to me too, because of the possible "filter injections", similar to the SQL-injection flaws.
- emn13 14y agoIt's also likely to be inherently hard to optimize; aka slow and will stay slow. I thinks it's a generally bad idea. It also undermines what limited tooling there is for JS; and it exposes Yet Another set of semantics - what exactly does that query do, how is it translated, what are the corner cases etc. Very Bad idea. (And for what - avoiding a few characters that are so common as to be trivially skimmable and very gzippable?)
- erikpukinskis 14y agoWhat do you think about jquery selectors? Do the same objections apply?
- aurelianito 14y agoCSS selectors also give me this bad feeling when used in javascript code.
- nadaviv 14y agoI think they do too. I used to fall-back to vanilla DOM queries sometimes when I started using jQuery, because it didn't feel quite right, and I always worried about the performance hit... but I ended up always using CSS selectors, unless there's a good reason not to. I think the main difference is that the value proposition of CSS selectors is just better than of the string-function syntax, so its worth it.
- deleted 14y ago[deleted]
- bjourne 14y agoIf you care about minor syntactical details like that, you should already be using coffeescript: select((o) -> o.x > 30) Seriously, it's great. :)