1.借用构造函数继承
// function Animal(type) {
// this.type = type;
// this.friends=[];
// }
// function Cat(name){
// Animal.call(this)
// this.name = name;
// }
// var cat = new Cat('蓝猫');
// var cat1 = new Cat('喵喵');
// cat.friends.push('蓝猫');
// cat1.friends.push('咪咪');
// console.log(cat.friends,cat1.friends);
2.原型链继承
// function Animal(type) {
// this.type = type;
// this.friends=[];
// }
// function Cat(name){
// this.name = name;
// }
// Animal.prototype.eat = function () {
// console.log('吃鱼')
// }
// //想让猫有type属性, Animal 放在Cat的原型链上
// Cat.prototype = new Animal('cat');//animal的实例 可以使用构造函数中的属性和方法,
// //也可以使用animal原型上的属性和方法
// var cat = new Cat('tom');
// console.log(cat.type);
// cat.eat()
// //私有属性变成共享属性
// var cat1 = new Cat('蓝猫');
// cat1.friends.push('红兔')
// console.log(cat.friends);
3.组合继承
// function Animal(type) {
// this.type = type;
// this.friends=[];
// }
// Animal.prototype.eat = function () {
// console.log('吃鱼');
// }
// function Cat(name,type){
// Animal.call(this,type)
// this.name = name;
// }
// Cat.prototype = new Animal();
// var cat = new Cat('蓝猫','中国猫');
// var cat1 = new Cat('喵喵');
// cat.friends.push('蓝猫');
// cat1.friends.push('咪咪');
// console.log(cat);
//父类构造函数 实例属性 声明了两次
4.寄生式组合继承
// function Animal(type) {
// this.type = type;
// this.friends=[];
// }
// Animal.prototype.eat = function () {
// console.log('吃鱼');
// }
// function Cat(name,type){
// Animal.call(this,type)
// this.name = name;
// }
// //只继承 父类构造函数的原型属性
// // function Temp() {
// // }
// // Temp.prototype = Animal.prototype;
// // Cat.prototype = new Temp()
// Cat.prototype = {
// __proto__:Animal.prototype
// }
// // Cat.prototype = new Animal();
// var cat = new Cat('蓝猫','中国猫');
// var cat1 = new Cat('喵喵');
// cat.friends.push('蓝猫');
// cat1.friends.push('咪咪');
// console.log(cat);
//父类构造函数 实例属性 声明了两次