TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Matches.js -- Powerful Pattern Matching for Javascript

96 点作者 natefaubion超过 12 年前

9 条评论

jpolitz超过 12 年前
Cool! Sucks that it has to be so stringly typed, but I can't see another alternative.<p>One concern:<p>"Each pattern will be tried in order until a match is found."<p>As far as I know, ECMAScript doesn't specify any enumerations on objects that obey an order... browsers do syntactic order, but it's by no means a guarantee. (e.g. <a href="http://stackoverflow.com/a/280861" rel="nofollow">http://stackoverflow.com/a/280861</a>)
评论 #4517804 未加载
评论 #4519367 未加载
OmarIsmail超过 12 年前
I didn't know I needed this until I saw it and had that A-HA moment when I realized how much cleaner this would make a lot of code. Instead of hiding away the logic in a bunch of conditionals this makes the overloading declarative which is great for maintenance.
评论 #4518841 未加载
评论 #4518843 未加载
username3超过 12 年前
What are some applications of pattern matching?
评论 #4517112 未加载
评论 #4516716 未加载
评论 #4517873 未加载
ntoshev超过 12 年前
I've played a bit with pattern matching as a DSL on top of JavaScript: <a href="http://jsfiddle.net/ntoshev/q8Ayw/1/" rel="nofollow">http://jsfiddle.net/ntoshev/q8Ayw/1/</a>
se85超过 12 年前
I've come across aspects of this functionality before in a couple of languages now, even psql, however looking at this JavaScript way of doing it, I have to question whether it helps code readability or hurts it.<p>edit: dyslexia
评论 #4517437 未加载
pooriaazimi超过 12 年前
For those interested: XRegExp (<a href="http://xregexp.com" rel="nofollow">http://xregexp.com</a>) is also relevant.<p>(Not a direct competitor to Matches.js, but has some nice features)
danh超过 12 年前
Something like this would make a great addition to CoffeeScript.
评论 #4518175 未加载
评论 #4519586 未加载
elliotlai超过 12 年前
i want this in js for a long time
dreamdu5t超过 12 年前
Awesome! This is so useful!