ES6类:是否可以从父类访问子类的构造函数? [英] ES6 classes: is it possible to access the constructor of a child class from the parent?
本文介绍了ES6类:是否可以从父类访问子类的构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用ES6类语法,是否可以从父类创建当前类的新实例?例如:
Using ES6 class syntax, is it possible to create a new instance of the current class from the parent? For example:
class Base {
withFoo() {
return new self({ foo: true });
}
}
class Child extends Base {}
(new Child()).withFoo();
我正在寻找与PHP new self()类似的东西
语法。
I'm looking for something similar to PHP's new self()
syntax.
推荐答案
您可以通过 this.constructor
。
这篇关于ES6类:是否可以从父类访问子类的构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文