<script type="text/javascript">???? function Parent(name){???? ???? this.name=name;???? }???? Parent.prototype.hi=function(){???? ???? console.log('你好,我是'+this.name);???? }???? function Child1(name,age){???? ???? Parent.call(this,name);???? }???? function Child2(name,age){???? ???? Parent.call(this,name);???? }???? Child1.prototype=new Parent();???? Child2.prototype=Object.create(Parent.prototype);???? // Child2.prototype.constructor=Child2;???? var child1=new Child1('小明',12);???? var child2=new Child2('小紅',13);???? child1.hi();???? console.log(child1);???? child2.hi();???? console.log(child2);</script>想問一下Object.create與new的區(qū)別?謝謝各位大佬。
繼承中Object.create與new的區(qū)別。
不太甜
2018-09-22 14:42:25