Home > Web Front-end > JS Tutorial > Examples of using hasOwnProperty and isPrototypeOf methods in js_javascript skills

Examples of using hasOwnProperty and isPrototypeOf methods in js_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:45:33
Original
1187 people have browsed it

hasOwnProperty: is used to determine whether an object has a property or object with the name you gave it. However, it should be noted that this method cannot check whether the object has the property in the prototype chain. 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. If so, it returns true, otherwise it returns false.

Copy code The code is as follows:

function siteAdmin(nickName,siteName){
this .nickName=nickName;
this.siteName=siteName;
}
siteAdmin.prototype.showAdmin = function() {
alert(this.nickName "is the webmaster of " this.siteName "! ")
};
siteAdmin.prototype.showSite = function(siteUrl) {
this.siteUrl=siteUrl;
return this.siteName "The address is " this.siteUrl;
} ;
var matou=new siteAdmin("Script Home","WEB Front-end Development");
var matou2=new siteAdmin("Script Home","WEB Front-end Development");
matou. age="30";
// matou.showAdmin();
// alert(matou.showSite("http://www.jb51.net/"));
alert(matou. hasOwnProperty("nickName"));//true
alert(matou.hasOwnProperty("age"));//true
alert(matou.hasOwnProperty("showAdmin"));//false
alert(matou.hasOwnProperty("siteUrl"));//false
alert(siteAdmin.prototype.hasOwnProperty("showAdmin"));//true
alert(siteAdmin.prototype.hasOwnProperty("siteUrl") );//false
alert(siteAdmin.prototype.isPrototypeOf(matou))//true
alert(siteAdmin.prototype.isPrototypeOf(matou2))//true
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template