javascript - 扩展窗口类
问题描述
我想将窗口类扩展为
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;
...
解决方案
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
推荐阅读
- android - 打开相机意图后设备屏幕变黑
- r - 根据行的条件将 NA 替换为值
- jmeter - 无法通过 jmeter webdriver 采样器发送邮件
- java - 我想在我的 spring Boot 项目中读取 Tomcat 中的 context.xml。我能怎么做?
- google-chrome - 如何在使用检查元素时停止重新加载
- html - 适合窗口的图像网格
- python - 使用 Python 替换最后一次出现的字符串
- c# - 如何有效地重构此代码?
- python - 网页抓取问题 - 返回空表
- node.js - Nodejs 如何将实时数据从 Firebase 发送到 Angular