class FooParent(object): def __init__(self): self.parent = 'I am the parent' print('Parent') def bar(self, message): print("%s from Parent" % message) class FooChild(FooParent): def __in
# super(type[, object-or-type]) ,调用父类方法class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print ('Parent') def bar(self, message): print ("%s from Parent" % message)
index.ts abstract class Foo { constructor() {} className = "Foo"; } class FooChild extends Foo { constructor() { super(); } } // const foo = new Foo(); // Error const fooChild = new FooChild(); fooChild.className; // "Foo&quo
1.描述 super() 用于调用父类。 super() 用来解决多重继承,直接用类名调用父类方法在单继承的时候是没有问题,但在多继承上,涉及查找顺序、重复调用等问题。 MRO 是类的方法解析顺序表,其实也是继承父类方法时的顺序表。 2.语法 super(type[, object-or-type]) 参数: type:类 object-o