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
红宝书第六章 羽哥写的继承镇楼
原型链继承的基本思想
利用原型,让一个引用类型继承另一个引用类型的属性和方法
题目:请写出原型链继承的示例,举例原型链继承的优缺点,使用原型链继承的场景
__
借用构造函数继承的基本思想
借用构造函数继承也叫做(伪造对象或经典继承),思想就是在子类型构造函数的内部调用超类型的构造函数
题目:请写出构造函数继承的示例,举例构造函数继承的优缺点,使用构造函数继承的场景
组合继承的基本思想
组合继承就是原型链继承+借用构造函数继承
题目:请写出组合继承的示例,举例组合继承的优缺点,使用组合继承的场景
The text was updated successfully, but these errors were encountered:
优点:
缺点:
场景:
例子:
function Parent() { this.name = 'parent' this.names = ['parent1', 'parent2'] } Parent.prototype.getName = function () { console.log(this.name); } function Child() { } Child.prototype = new Parent(); var child1 = new Child(); var child2 = new Child(); child1.getName(); child1.names.push('parent3') console.log(child1.names, child2.names);
function Parent(name) { this.name = name; this.names = ['parent1', 'parent2'] } function Child(name) { Parent.call(this, name); } var child1 = new Child('child1'); var child2 = new Child(); child1.names.push('parent3'); console.log(child1.names, child2.names, child1.name);
function Parent(name) { this.name = name; this.names = ['parent1', 'parent2'] } Parent.prototype.getName = function () { console.log(this.name); } function Child(name) { Parent.call(this, name); } Child.prototype = new Parent(); Child.prototype.constructor = Child; var child1 = new Child('child1') var child2 = new Child('child2'); child1.names.push('parent3') child1.getName(); console.log(child1.names, child2.names, child1.name, child2.name);
Sorry, something went wrong.
No branches or pull requests
红宝书第六章
羽哥写的继承镇楼
利用原型,让一个引用类型继承另一个引用类型的属性和方法
__
借用构造函数继承也叫做(伪造对象或经典继承),思想就是在子类型构造函数的内部调用超类型的构造函数
__
组合继承就是原型链继承+借用构造函数继承
The text was updated successfully, but these errors were encountered: