//原型的继承 改变构造函数的原型不是继承// 给构造函数的原型的原型去继承 也就是给Object的原型// 使用create方法 创建一个新的对象 它会创建一个新的对象// function Hd() { }// console.dir(Hd);function User(age) { this.age = age this.name = 'user'}function Admin(age) { User.call(this, age) this.name = 'admin'}function Member(age) { User.call(this, age) this.name = 'member'}User.prototype.view = function () { console.log(this.age);}// Admin.prototype.role = function () {// console.log(this.name);// }// Member.prototype.role = function () {// console.log(this.name);// }// User继承Admin的方法// 继承的方法 1 直接在构造函数的原型的原型// 方法一// Admin.prototype.__proto__ = User.prototype// Member.prototype.__proto__ = User.prototype// 方法二 使用setPrototypeOf// Object.setPrototypeOf(Member.prototype, User.prototype)// Object.setPrototypeOf(Admin.prototype, User.prototype)// 方法三 使用Object.create方法实现 使用这种方法的问题就是 它会生成一个新的对象,并且将该对象的原型指向// 这个函数的原型Admin.prototype = Object.create(User.prototype)Member.prototype = Object.create(User.prototype)// // 将constructor的属性设置为不可遍历的参数// Object.defineProperty(Admin.prototype, 'constructor', {// value: Admin,// enumerable: false// })// Admin.prototype.role = function () {// console.log(this.name);// }// Member.prototype.role = function () {// console.log(this.name);// }// 方法四// 使用call方法来继承 寄生式组合继承// 使用Object.create 方法和call方法还有apply方法来实现继承,但是也必须使用defineProperty方法来将constructor的值设置为不可遍历的属性let member = new Member(12)let admin = new Admin(21)// console.dir(admin);// // admin.role()// // member.role()member.view()admin.view()// console.log(member.);