国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js中的hasOwnProperty和isPrototypeOf方法使用實例

2019-11-20 14:46:02
字體:
來源:轉載
供稿:網友

hasOwnProperty:是用來判斷一個對象是否有你給出名稱的屬性或對象。不過需要注意的是,此方法無法檢查該對象的原型鏈中是否具有該屬性,該屬性必須是對象本身的一個成員。

isPrototypeOf:是用來判斷要檢查其原型鏈的對象是否存在于指定對象實例中,是則返回true,否則返回false。

復制代碼 代碼如下:

function siteAdmin(nickName,siteName){
 this.nickName=nickName;
 this.siteName=siteName;
}
siteAdmin.prototype.showAdmin = function() {
 alert(this.nickName+"是"+this.siteName+"的站長!")
};
siteAdmin.prototype.showSite = function(siteUrl) {
 this.siteUrl=siteUrl;
 return this.siteName+"的地址是"+this.siteUrl;
};
var matou=new siteAdmin("武林網","WEB前端開發");
var matou2=new siteAdmin("武林網","WEB前端開發");
matou.age="30";
//  matou.showAdmin();
//  alert(matou.showSite("http://www.survivalescaperooms.com/"));
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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无棣县| 尉氏县| 上饶市| 新疆| 日照市| 新津县| 都江堰市| 徐汇区| 岱山县| 建始县| 郴州市| 鄂州市| 雅安市| 清新县| 新竹县| 阳朔县| 察哈| 比如县| 镇沅| 舒兰市| 广水市| 洞口县| 兴和县| 灌南县| 凤城市| 调兵山市| 九江县| 龙海市| 嘉兴市| 阳城县| 娱乐| 胶州市| 黄浦区| 富平县| 临泉县| 格尔木市| 宁都县| 固镇县| 新兴县| 寿宁县| 滨海县|