我有下面的構造:js函數將多個參數傳遞作爲單個對象
var one = new HB.hideShowFacilites.Selectors(".facilities .more-centered", "more-centered", "less-centered", "container-max-height", ".facilities .container-min-height");
有沒有經過所有這些選擇的作爲單個對象的一種方式?
HB.hideShowFacilites = HB.hideShowFacilites || {};
HB.hideShowFacilites.Selectors = function(sel1, sel2, sel3, sel4, sel5){
this.sel1 = sel1;
this.sel2 = sel2;
this.sel3 = sel3;
this.sel4 = sel4;
this.sel5 = sel5;
};
HB.hideShowFacilites.Selectors.prototype.hideShow = function(){
var $obj1 = $(this.sel1),
$obj2 = this.sel2,
$obj3 = this.sel3;
$obj4 = this.sel4,
$obj5 = $(this.sel5);
$obj1.on('click', function(e){
e.preventDefault();
if($obj1.hasClass($obj2)){
$obj1.removeClass($obj2).addClass($obj3);
$obj5.addClass($obj4);
}
else{
$obj1.removeClass($obj3).addClass($obj2);
$obj5.removeClass($obj4);
}
});
};
$(document).ready(function(){
var one = new HB.hideShowFacilites.Selectors(".facilities .more-centered", "more-centered", "less-centered", "container-max-height", ".facilities .container-min-height");
one.hideShow();
});
發送作爲數組'[ 「.facilities更多爲中心」, 「多中心」, 「少爲中心」,「CONTA iner-max-height「,」.facilities .container-min-height「]' – Dhiraj
什麼是HB.hideShowFacilites.Selectors()查找? – stackoverfloweth
不夠清楚,你是否想將值作爲一個對象傳遞給函數,還是使用傳入的參數,因爲它們是一個對象,或者兩者都傳遞和處理參數,因爲它們是一個對象? – skazska