The Name property is either accessed directly on the object or is accessed through a prototype. Therefore, calling name in person always returns true regardless of whether the attribute exists in the instance or exists in the prototype. hasOwnProperty () returns true only in the instance.
function Hasprototypeproperty (object, name) {
return!object.hasownproperty (name) && (name in object);
}
If the function returns True, this property is indicated in the prototype. Otherwise the Description property is in the instance, or the property does not exist.
function person () {
Person.prototype.name = "Nicholas";
Person.prototype.sayname = function () {
alert (this.name);
}
}
var persion = new Person ();
Alert (Hasprototypeproperty (Person,name));//true
Person.name = "Xupen";
Alert (Hasprototypeproperty (Person,name));//false
JS prototype mode