考虑:
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