我想了解的对象和功能比较运营商,这是我的代码:与布尔总是返回false
function house(roof) {
this.roof = roof;
this.roofdescrip = describehouse();
}
function describehouse(){
var z = this.roof;
x="The house has a roof.";
y="The house does not have a roof.";
if(z===true){return x;}
else{return y;}
}
var myhouse = new house(true);
document.write(myhouse.roofdescrip);
总是返回
The house does not have a roof.
我是否更改参数为true或false 。为什么?
Triple =比较类型。不确定这是否是问题,但是在这里您将屋顶与布尔值进行比较? – Andromelus
'describehouse'不是'myhouse'的*方法*,所以当你这样称呼'this'时不起作用 – Bergi