function foo(params){
this.name=params.name||"andi";
this.age=params.age||"23";
this.class=params.class||"7";
this.bool=params.bool||true;
}
var nf=new foo({
name:"xl",
class:"2",
bool:false
});
console.log(nf);
这种打印出来
布尔值并没有按照我想要重置,我知道是false||true的原因而得到了true,请问我要怎么写才能在将其正确实例化??
用&&也不能完全满足
那你是想怎么样才置为true。。。
this.bool = Object.prototype.toString.call(params.bool) === '[object Boolean]'?params.bool:true
this.bool = params.bool === false ? false : true;