这是我的代码:
function function1() {
var ids = GetIds(); // predefined function
if (ids.length === 0) {
alert("Please select at least one item to procees.");
return;
}
...
}
function function2() {
var ids = GetIds(); // predefined function
if (ids.length === 0) {
alert("Please select at least one item to procees.");
return;
}
...
}
function function3() {
var ids = GetIds(); // predefined function
if (ids.length === 0) {
alert("Please select at least one item to procees.");
return;
}
...
}
如何提取公共部分?如何重构代码?return 语句很难处理。是否有任何与重构此代码有关的模式?
提前致谢!
if (ids.length === 0) {
alert("Please select at least one item to procees.");
return;
}