hasOwnProperty: is used to determine whether an object has a property or object that you give a name to. However, it is important to note that this method cannot check whether the object has this property in its prototype chain, and that the property must be a member of the object itself.
isPrototypeOf is used to determine whether the object whose prototype chain is to be checked exists in the specified object instance, or True, otherwise returns false.
functionSiteAdmin (nickname,sitename) { This. nickname=nickname; This. sitename=SiteName; } siteAdmin.prototype.showAdmin=function() {alert ( This. nickname+ "Yes" + This. sitename+ "the webmaster!") }; SiteAdmin.prototype.showSite=function(siteurl) { This. siteurl=SiteURL; return ThisThe address of the. sitename+ "is" + This. SiteURL; }; varmatou=NewSiteAdmin ("Fool's Wharf", "Web front-end development"); varMatou2=NewSiteAdmin ("Fool's Wharf", "Web front-end development"); Matou.age= "30";//matou.showadmin ();//Alert (Matou.showsite ("http://www.css88.com/"));Alert (Matou.hasownproperty ("nickname"));//trueAlert (Matou.hasownproperty ("Age"));//trueAlert (Matou.hasownproperty ("showadmin"));//falseAlert (Matou.hasownproperty ("SiteURL"));//falseAlert (SiteAdmin.prototype.hasOwnProperty ("showadmin"));//trueAlert (SiteAdmin.prototype.hasOwnProperty ("SiteURL"));//falseAlert (SiteAdmin.prototype.isPrototypeOf (Matou))//trueAlert (SiteAdmin.prototype.isPrototypeOf (MATOU2))//true
1 for in can get all the properties of an object, including custom attributes and prototype chain properties.
for (var attr in object) {
Console.log (attr+ ":" object[attr]);
}
2 hasOwnProperty () can only get custom properties and cannot get prototype chain properties.
"Str". hasOwnProperty ("split");//false
String.property.hasOwnProperty ("split");//true
hasOwnProperty and isprototypeof in JavaScript