function User(username) {
this.username = username ? username : "Unknown";
this.books = ["coffe", "1891"];
User.prototype.read = function () {
console.log(this.username + '喜欢读的书是:' + this.books.join("/"));
function CoffeUser(username) {
this.username = username;
CoffeUser.prototype = new User();
const user1 = new CoffeUser("bob");
const user2 = new CoffeUser("steve");
//instanceof是检测某个对象是否是某个类的实例
console.log(user1 instanceof User); //>> true
console.log(user1.books); //>> ["coffe", "1891"]
user1.read();//>> bob喜欢读的书是:coffe/1891
user2.read();//>> steve喜欢读的书是:coffe/1891
//修改来自原型上的引用类型的属性,则有副作用:会影响到所有实例
user1.books.push("hello");
console.log(user1.books); //>> ["coffe", "1891", "hello"]
console.log(user2.books); //>> ["coffe", "1891", "hello"]
console.log(user1.username, user2.username); //>> bill steve