![](/img/trans.png)
[英]ES6 using static method to create new instance gives undefined for child class attributes
[英]Create new instance of this using ES6
是否可以在靜態方法中使用ES6創建self / this的新實例? 例如;
class myClass {
static model() {
return new this;
}
}
這種情況是否存在公認的模式?
非常感謝。
是的,這就是您的做法。
如果您不希望子類使用子類構造函數,則可以通過名稱顯式地引用您的類,類似於訪問其他靜態方法 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.