我有下面的构造: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