原型继承
当原型中存在引用类型,存在数据被修改的问题
<script> function Box() { this.name="lee"; } function Desk() { this.age="22"; } Desk.prototype=new Box();//Desk继承了Box形参了原型链 var desk=new Desk(); // console.log(desk.name+desk.age) function Table() { this.level="AAAAA"; } Table.prototype=desk; var tab=new Table(); console.log(desk instanceof Table) </script>
发表评论: