The hasOwnProperty and isPrototypeOf methods in JS

Source: Internet
Author: User
Tags hasownproperty

Transferred from: http://www.cnblogs.com/jenry/archive/2010/12/08/1900150.html

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.

Instance try:

function SiteAdmin (nickname,sitename) { This. nickname=nickname;  This. sitename=SiteName; } siteAdmin.prototype.showAdmin=function () {alert ( This. nickname+"is a"+ This. sitename+"the webmaster!");        }; SiteAdmin.prototype.showSite=function (siteurl) { This. siteurl=SiteURL; return  This. sitename+"the address is"+ This. SiteURL;        }; varmatou=NewSiteAdmin ("Fool's Wharf","Web front-end development"); varMatou2=NewSiteAdmin ("Fool's Wharf","Web front-end development"); Matou.age=" -";//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.