SOURCE

// 你 getPrototypeOf()和SetPrototypeOf()

let food = {
  getDrink(){
    return 'coffe';
  }
}

let breakfast = {
  getDrink(){
    return 'tea';
  }
}

let source = Object.create(food);
console.log(source.getDrink())
console.log(Object.getPrototypeOf(source)===food);


Object.setPrototypeOf(source,food);
console.log(source.getDrink());

// __proto__ 设置 protoType
//设置protoType
let source2 = {
  __proto__:food
};

console.log(source2.getDrink());
console.log(Object.getPrototypeOf(source2)===food);

//设置protoType
source2.__proto__=breakfast;
console.log(source2.getDrink());
console.log(Object.getPrototypeOf(source2)===breakfast);


//super 用法 和方法名一起用,重写父类的方法
let source3 = {
  __proto__:food,
  //  更改food的getDrink()方法
  getDrink(){
    return super.getDrink()+' milk';
  }
};
console.log(source3.getDrink());

console 命令行工具 X clear

                    
>
console