代码描述:对象获取 原型对象。对象获取原型对象
本章节介绍一下如何获取一个对象实例的原型对象。 实现此功能的常用方法有两种,下面就分别做一下简单介绍。 实现方式一:
<script> function Antzone(){ this.webName="51前端"; } Antzone.prototype.show=function(){ console.log(this.webName); } var antzone=new Antzone(); console.log(antzone.__proto__==Antzone.prototype); </script>
使用__proto__即可获取对象的原型,但是IE11以下浏览器并不支持。 实现方式二:
<script> function Antzone(){ this.webName="51前端"; } Antzone.prototype.show=function(){ console.log(this.webName); } var antzone=new Antzone(); console.log(antzone.constructor.prototype==Antzone.prototype); </script>
上面的方式也可以实现,并且兼容所有的主流浏览器。
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能