相关疑难解决方法(0)

扩展HTMLElement:使用webpack时构造函数失败

我将以下TypeScript程序转换为ES5:

档案1:

class BaseElement extends HTMLElement {
    constructor() {
        super();
    }
}
Run Code Online (Sandbox Code Playgroud)

文件2:

import {BaseElement} from './BaseElement';

class MyElement extends BaseElement {
    constructor() {
        super();
    }
}

var el = new MyElement();
Run Code Online (Sandbox Code Playgroud)

将所有内容手动放入文件中,代码工作正常并在浏览器中执行,HTMLElement构造没有问题.但是,只要我通过webpack打包它,我收到以下错误消息:

Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Run Code Online (Sandbox Code Playgroud)

没有webpack,构造了以下JS代码:

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor …
Run Code Online (Sandbox Code Playgroud)

javascript web-component typescript webpack

19
推荐指数
2
解决办法
8421
查看次数

如何从DOM元素类继承

我想编写一些扩展DOM节点的Javascript类(这样我就可以直接将我的类的实例插入到DOM中),但是我很难找到我应该继承的类/原型.

例如:

function myExtendedElement() {
       this.superclass = ClassA;
       this.superclass();
       delete this.superclass;
} 
Run Code Online (Sandbox Code Playgroud)

但ClassA应该是什么?

javascript inheritance dom

7
推荐指数
1
解决办法
8369
查看次数