We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 寄生组合继承 function Father(name) { this.name = name this.city = '北京' } Father.prototype.getName = function () { return this.name } function Child(name, age) { Father.call(this, name) // 继承属性 this.age = age } // 继承方法 等价于 Child.prototype.__proto__ = Father.prototype Child.prototype = Object.create(Father.prototype) // 原型链 Child.prototype.constructor = Child // 原型链,注意这里的构造函数是指回 Child Child.prototype.getAge = function () { return this.age } var child = new Child('lmh', 25) var myname = child.getName() var age = child.getAge() console.log(myname) console.log(age)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: