【发布时间】:2012-09-22 12:42:38
【问题描述】:
目前我有这样的代码..
var result = line.match( some regexp );
if (result !== null) {
return callback({ a: 'aaaaa', b: bvariable });
});
}
var result = line.match( some other regexp );
if (result !== null) {
return callback({ d: 'ddddd', c: bvariable });
});
}
我有大约 10 个这些都具有不同的正则表达式和回调,并且列表会变得更大。有没有更好/更清洁的方法?
【问题讨论】:
-
您需要展示更多
if块的外观,以便我们知道该代码中有多少共性。 -
我在大约 5 年后查看了这个问题,但仍然没有得到满意的答案,以避免通过代码进行多次存在性检查。
-
如果我没记错的话,没有办法绕过多行 if 语句作为返回对象的内容,其中依赖于匹配的正则表达式。
标签: javascript node.js