Xem xét:
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đã gọi vào body.onloadsự kiện.
Tôi mong đợi shape1.hasOwnProperty(name)trả về true, nhưng nó lại trả về false.
Hành vi đúng là gì?
"name"trái ngược vớiname