【发布时间】:2017-04-01 20:28:38
【问题描述】:
我正在尝试理解对象和函数,这是我的代码:
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 = 也比较类型。不确定这是否是问题所在,但在这里您将屋顶与布尔值进行比较?
-
describehouse不是myhouse的方法,所以this在你这样称呼它时不起作用
标签: javascript html string comparison string-comparison