先看一下代碼: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構造函數的,那為什么Child實例會有name屬性呢?
javascript中,子類為什么會繼承父類的構造函數中的屬性?
手掌心
2018-12-21 18:14:25