继承的练习
html head title继承/title /head body h12026.3.18 周三 继承/h1 script // 父类 Animal 私有属性 type function Animal(type) { this.type type; } // 父类 Animal 共有方法 eat Animal.prototype.eat function () { console.log(this.type 正在吃东西); }; // 子类 Dog 私有属性name function Dog(name, type) { // 继承父类的私有属性 Animal.call(this, type); this.name name; } // 子类 Dog 继承父类 Animal 的共有方法 Dog.prototype new Animal(); // 修复子类 Dog 的 constructor 指向 Dog.prototype.constructor Dog; // 子类 Dog 共有方法 bark Dog.prototype.bark function () { console.log(this.name 正在汪汪叫); }; var dog new Dog(旺财, 狗); dog.eat(); dog.bark(); /script /body /html