一、hasOwnProperty vs isPrototyOf
1&2互为补充
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前端开发");
1. hasOwnProperty: 对象求属性,但是不包括原型链里的。
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
2. isPropertyof对象是否继承与某个原型链。 判断某个原型链,该对象有没有继承。
alert(siteAdmin.prototype.isPrototypeOf(matou))//true
二、object.create (shadowcopy and 原型链继承) / object freeze
原文:https://www.cnblogs.com/connie313/p/13379139.html