代码描述:javascript使用call()函数。javascript使用call()函数继承代码下载
本章节分享一段代码实例,它是使用call()函数实现了继承效果,当然也可以使用其他方式实现继承,例如使用原型方式,这里就不介绍了,具体可以参阅 javascript prototype原型一章节,关于call()函数的用法可以参阅js call()一章节。 代码实例如下:
<script> function Antzone(webName){ this.webName=webName; this.show=function(){ console.log("网站名称: "+this.webName); } } function Done(webName,target){ Antzone.call(this,webName); this.target=target; this.dshow=function(){ console.log("target: "+this.target); } } var oantzone=new Antzone("51前端"); oantzone.show(); var odone=new Done("51前端","分享互助"); odone.show(); odone.dshow(); </script>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能