先看一下代碼:function Parent(name){ this.name = "liu";}function Child(age){ this.age = age;}Child.prototype = new Parent();var child1 = new Child(19);alert(child1.name+" "+child1.age);//liu 19Child明明繼承的是Parent的prototype,而name屬性是屬于Parent構(gòu)造函數(shù)的,那為什么Child實(shí)例會(huì)有name屬性呢?
javascript中,子類為什么會(huì)繼承父類的構(gòu)造函數(shù)中的屬性?
手掌心
2018-12-21 18:14:25