首页 > 解决方案 > 扩展窗口类

问题描述

我想将窗口类扩展为

window.Physics = class Physics extends window.Trait

但它崩溃了

Uncaught (in promise) TypeError: window.Physics is not a constructor

编辑:特质.js

window.Trait = class Trait {
constructor(name) {
    this.NAME = name;
...

标签: javascriptclasswindow

解决方案


You need to create Class Physics with a constructor just like a Trait and then you can extend Physics. It's impossible to do without a constructor.

You can read about class inheritance here https://javascript.info/class-inheritance


推荐阅读