我想了解的對象和功能比較運營商,這是我的代碼:與布爾總是返回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