【发布时间】:2010-04-08 13:17:48
【问题描述】:
考虑:
function Shape() {
this.name = "Generic";
this.draw = function() {
return "Drawing " + this.name + " Shape";
};
}
function welcomeMessage()
{
var shape1 = new Shape();
//alert(shape1.draw());
alert(shape1.hasOwnProperty(name)); // This is returning false
}
.welcomeMessage 调用了body.onload 事件。
我希望 shape1.hasOwnProperty(name) 返回 true,但它返回 false。
正确的行为是什么?
【问题讨论】:
-
它需要一个字符串,所以
"name"而不是name
标签: javascript