使这三个函数更高效的最佳方法是什么?他们分享逻辑。组合函数以降低复杂性
function setBoxWidth(type) {
var boxWidth;
if (type) {
boxWidth = 308;
} else {
boxWidth = 400;
}
return boxWidth;
}
function setAspectWidth(type) {
var bw;
if (type) {
bw = 192;
} else {
bw = 100;
}
return bw;
}
function setAspectHeight(type) {
var bh;
if (type) {
bh = 47;
} else {
bh = 100;
}
return bh;
}
我访问他们像这样:
function useJcrop(img, type, boxWidth) {
var aspect,
bh = setAspectHeight(type),
bw = setAspectWidth(type),
bWidth =setBoxWidth(type);
}
我看不到哪种类型被赋值。 –
对不起,我的错。我做了编辑。这是useJcrop函数中的一个参数。 – webbydevy
他们必须是功能吗? –