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 A() { this.a = "a"; } function B() { this.b = "b"; } //B继承A B.prototype = new A(); B.prototype.constructor = B;
利用原型让一个引用类型继承另一个引用类型的属性和方法
借用构造函数继承
function A() { this.a = "a"; } function B() { this.b = "b"; //B继承A A.call(this); }
在子类构造函数的内部调用父类构造函数
组合继承(原型+借用构造函数)
function A() { this.a = "a"; } function B() { this.b = "b"; //B继承A A.call(this); } //B继承A B.prototype = new A(); B.prototype.constructor = B;
原型式继承
function A() { this.a = "a"; } function B() { this.b = "b"; } //B继承A B.prototype = Object.create(A.prototype); B.prototype.constructor = B;
借助原型可以基于已有的对象创建新的对象
寄生式继承
function A() { this.a = "a"; } function B() { this.b = "b"; //B继承A let obj = new A; for (const key in obj) { this[key] = obj[key] } obj = null; }
在子类的构造函数中增加父类的属性和方法
寄生组合式继承(推荐)
function A() { this.a = "a"; } function B() { this.b = "b"; //B继承A let obj = new A; for (const key in obj) { if (obj.hasOwnProperty(key)) { this[key] = obj[key] } } obj = null; } //B继承A B.prototype = Object.create(A.prototype); B.prototype.constructor = B;
通过构造函数来继承属性,通过原型链来继承方法
ES6中的继承
class A { constructor() { this.a = "a" } } class B extends A { //B继承A }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原型链继承
利用原型让一个引用类型继承另一个引用类型的属性和方法
借用构造函数继承
在子类构造函数的内部调用父类构造函数
组合继承(原型+借用构造函数)
原型式继承
借助原型可以基于已有的对象创建新的对象
寄生式继承
在子类的构造函数中增加父类的属性和方法
寄生组合式继承(推荐)
通过构造函数来继承属性,通过原型链来继承方法
ES6中的继承
The text was updated successfully, but these errors were encountered: