) Hasownproperty and isprototypeof methods in JS

Source: Internet
Author: User

hasownproperty: used to determine whether an object has an attribute or object with the name given by you. However, you must note that this method cannot check whether the property exists in the prototype chain of the object. The property must be a member of the object.
isprototypeof is used to determine whether the object of the prototype chain exists in the specified object instance. If yes, true is returned. Otherwise, false is returned.

 function siteadmin (nickname, sitename) {This. nickname = nickname; this. sitename = sitename;} siteadmin. prototype. showadmin = function () {alert (this. nickname + "yes" + this. sitename + "webmaster! ")}; Siteadmin. prototype. showsite = function (siteurl) {This. siteurl = siteurl; return this. the address of sitename + "is" + this. siteurl ;}; var Matou = new siteadmin ("", "Web Front-end development"); var matou2 = new siteadmin ("", "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 

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.