我想知道是否有人可以帮我改进这段代码,在我看来这不是一个很好的执行功能有没有办法减少行中的这个功能?
这是我的功能:
function changeStyling(input, changeSelector, elementCssChange, pixels) {
if(!reload){
if(changeSelector === '.exit-intent-wrapper' && elementCssChange === 'background') {
this.base64PopupBGImg = null, document.querySelector(changeSelector).style[elementCssChange] = `${input.value}`;
}
pixels ?
document.querySelector(changeSelector).style[elementCssChange] = `${input.value}px` :
document.querySelector(changeSelector).style[elementCssChange] = `${input.value}`;
} else {
pixels[i] ? document.querySelector(changeSelector[i]).style[elementCssChange[i]] = `${input[i].value}px` : document.querySelector(changeSelector[i]).style[elementCssChange[i]] = input[i].value;
for (i = 0; i < arguments.length; i++) {
}
}
}
这就是我在重装时执行它的方式:
changeStyling(
[
document.querySelector(".exitIntentWidth"),
document.querySelector(".exitIntentHeight"),
document.querySelector(".exitIntentRadius"),
document.querySelector(".exitIntentPaddingAll"),
document.querySelector(".exitIntentPadding"),
document.querySelector(".exitIntentPaddingLeft"),
document.querySelector(".exitIntentPaddingRight"),
document.querySelector(".btnWidth"),
document.querySelector(".btnHeight"),
document.querySelector(".btnRadius"),
document.querySelector(".btnColor"),
document.querySelector(".btnTextColor")
],
[
'.exit-intent-wrapper',
'.exit-intent-wrapper',
'.exit-intent-wrapper',
'.exit-intent-wrapper',
'.exit-intent-inner',
'.exit-intent-inner',
'.exit-intent-inner',
'.button',
'.button',
'.button',
'.button',
'.button'
],
[
'width',
'height',
'borderRadius',
'padding',
'padding',
'paddingLeft',
'paddingRight',
'width',
'height',
'borderRadius',
'backgroundColor',
'color'
],
[ true, true, true, true, true, true, true, true, true, true, false, false ]
);
有人知道如何减少函数的执行吗?
答案 0 :(得分:1)
您的代码目前使用并行数组,这些数组非常混乱且难以修改。我建议使用多维数组或对象。
Couldn't match type ‘b’ with ‘b1’
‘b’ is a rigid type variable bound by
the instance declaration at Test.hs:31:10
‘b1’ is a rigid type variable bound by
the type signature for f :: Maybe b -> b1 at Test.hs:32:3
Expected type: Maybe b -> b1
Actual type: Maybe b1 -> b1
Relevant bindings include
f :: Maybe b -> b1 (bound at Test.hs:32:3)
In the expression: fMaybe
In an equation for ‘f’: f = fMaybe
请注意,我还没有测试过此代码,它可能无法正常运行