javascript - 对象里面布尔值重置
本文介绍了javascript - 对象里面布尔值重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
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,请问我要怎么写才能在将其正确实例化??
用&&也不能完全满足
解决方案
this.bool = params.bool === false ? false : true;
这篇关于javascript - 对象里面布尔值重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文