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

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

作者: 字体:[增加 减小] 类型:转载 时间:2014-06-06 我要评论

这篇文章主要介绍了js中的hasOwnProperty和isPrototypeOf方法使用实例,需要的朋友可以参考下
id="iframeu2261530_0" src="http://pos.baidu.com/acom?sz=680x200&rdid=2261530&dc=2&di=u2261530&dri=0&dis=0&dai=2&ps=403x80&coa=at%3D3%26rsi0%3D680%26rsi1%3D200%26pat%3D6%26tn%3DbaiduCustNativeAD%26rss1%3D%2523FFFFFF%26conBW%3D1%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D14%26rss2%3D%2523000000%26titSU%3D0%26ptbg%3D90%26piw%3D0%26pih%3D0%26ptp%3D0&dcb=BAIDU_UNION_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1457591461112&ti=js%E4%B8%AD%E7%9A%84hasOwnProperty%E5%92%8CisPrototypeOf%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B_javascript%E6%8A%80%E5%B7%A7_%E8%84%9A%E6%9C%AC%E4%B9%8B%E5%AE%B6&ari=1&dbv=2&drs=1&pcs=1151x549&pss=1151x409&cfv=0&cpl=4&chi=1&cce=true&cec=GBK&tlm=1457109348&ltu=http%3A%2F%2Fwww.jb51.net%2Farticle%2F50757.htm&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DLtM7-ST_m6ZGgp7dkBNPkMXQC7emcj_OUNKxV10Ly6RneMUFUzRPFBXx4N5dfR3m%26wd%3D%26eqid%3Dcd0c825b0000d5eb0000000556e11464&ecd=1&psr=1366x768&par=1366x728&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1457591461&qn=a0b4891fb8e97490&tt=1457591461089.101.227.228" width="680" height="200" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="display: block; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">

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.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值