使這三個函數更高效的最佳方法是什麼?他們分享邏輯。組合函數以降低複雜性
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
他們必須是功能嗎? –