个人学习笔记,欢迎大佬们纠错
function Person(name) {
this.name = name
}
Person.prototype.say = function () {
console.log(`Hi! I‘m ${this.name}`)
}
function Man(name, age) {
Person.call(this, name)
this.age = age
}
function inherit(sup, sub) {
let prototype = Object.create(sup.prototype)
sub.prototype = prototype
prototype.constructor = sub
}
inherit(Person, Man)
Man.prototype.sayAge = function () {
console.log(`I'm ${this.age}`)
}
Man.prototype.sex = 'Male'
let Mike = new Man('Mike', 18)
Mike.say()
Mike.sayAge()